-
Notifications
You must be signed in to change notification settings - Fork 18.1k
cmd/go2go: assignment type checking does not work correctly #39930
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
CC @griesemer I'm not sure the type checker is wrong here. You have a type parameter |
The problem is here Lines 233 to 234 in 71c7be5
Vu := optype(V.Under()) // V represents type of a result of New function, so Vu is *types.Interface bound by three methods
Tu := optype(T.Under()) // T represents type param I, so optype function returns types.top That's what happens when func optype(typ Type) Type {
if t := typ.TypeParam(); t != nil { // I is a type param
if u := t.Bound().allTypes; u != nil && u != typ { // t bound only by method list, not by type list, so allTypes is nil
return u.Under()
}
return theTop // here function returns
}
return typ
} I tried to fix it changing func optype(typ Type) Type {
if t := typ.TypeParam(); t != nil {
// If the optype is typ, return the top type as we have
// no information. It also prevents infinite recursion
// via the TypeParam converter methods. This can happen
// for a type parameter list of the form:
// (type T interface { type T }).
// See also issue #39680.
bound := t.Bound()
if u := bound.allTypes; u != nil && u != typ {
// u != typ and u is a type parameter => u.Under() != typ, so this is ok
return u.Under()
}
if u := bound.allMethods; u != nil {
return bound
}
return theTop
}
return typ
} then code compiles, but it breaks some standard libraries in |
This example does not compile too, it's literally func curry(type
IA, IB, RA, RB interface{},
I Tuple(IA, IB),
R Tuple(RA, RB),
)(a IA, fn func(t I) R) func(IB) R {
return func(b IB) R {
return fn(New(IA, IB)(a, b))
}
} |
This is not a bug; @ianlancetaylor has explained the reason already. Here's a simplified version of the code, hopefully making this more clear: package p
type Tuple interface {}
type tuple struct {}
func _(type I Tuple) () {
var v I
var t Tuple
v = t // <<<< ERROR: cannot use t (variable of type Tuple) as I value in assignment
_ = v
} Passing the result of The point is that the type of In summary, this is working as intended. Closing. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
n/a
What operating system and processor architecture are you using (
go env
)?What did you do?
https://go2goplay.golang.org/p/jmaTevSNW0X
What did you expect to see?
Successful compilation.
What did you see instead?
Unrelated bug from #39754 (comment)
The text was updated successfully, but these errors were encountered: