-
Notifications
You must be signed in to change notification settings - Fork 18.1k
cmd/go2go: conversion using type lists #39962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Relatedly, it looks like the following more specialized function gives the same error: func ConvertToString(type T interface{ type string })(t T) string {
return string(t)
} |
CC @griesemer I think that strictly speaking the design draft says that this code should not compile. It's an interesting case, though. |
The reason I say that it maybe should not compile is that your argument hinges on the underlying type of |
I think both design draft and spec refer to underlying types on both sides in the relevant contexts? Not that I would be particularly sad if it didn't, as long as it's clear: this code didn't end up being very useful to me for other reasons. |
First case is similar a bit to #39930 (comment).
Second example fails here Line 269 in 6cf6bf1
Underlying types are identical, but both are Named. |
@tdakkota That may be the reason for this failure but not the reasoning as to why it shouldn't fail. @ianlancetaylor has pointed at the culprit: The outcome hinges on what the underlying type of a type parameter is. One answer is that it is described by the type list in its constraint. Another one is that the underlying type of a type parameter is itself. Currently we implement the latter. The correct answer may be some variation of the former. This is under active investigation. |
The first example here is not valid code with Go 1.18. The second example (adjusted) works now as expected. Closing. |
Consider the following code (playground):
It does not compile, with the error:
It seems to me like this should compile: the design says
which I understand to mean the underlying type of
U
must be identical to the underlying type ofT
; the spec gives that as a sufficient condition to allowU(t)
.The text was updated successfully, but these errors were encountered: