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
cmd/compile: type inference appears to infer underlying types #50426
Comments
CC @griesemer |
This appears to be an issue (possibly a couple of issues) with type inference. Here's a simpler reproducer: package p
type A1 [2]uint64
type A2 [2]uint64
func (a A1) m() A1 { return a }
func (a A2) m() A2 { return a }
func f[B any, T interface{A1|A2; m() T}](v T) {}
func _() {
var v A2
f[A2](v)
} Error: Providing an (arbitrary) type argument for I also note that in the original example, there's a difference between Also, providing all type arguments explicitly ( |
The cause here is that - per the current algorithm for type inference - constraint type inference infers the wrong type: in the instantiation In the original example, when adding the cc: @ianlancetaylor |
Change https://golang.org/cl/377594 mentions this issue: |
Until now, CTI (constraint type inference) was run before FTI (function type inference). This lead to situations where CTI infered a type that is missing necessary methods even though a function argument of correct type was given. This can happen when constraint type inference produces a inferred type that is the structural type of multiple types, which then is an underlying type, possibly without methods. This CL removes the initial CTI step; it is only applied after FTI with type arguments is run, and again after FTI with untyped arguments is run. Various comments are adjusted to reflect the new reality. Fixes golang#50426. Change-Id: I700ae6e762d7aa00d742943a2880f1a1db33c2b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/377594 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
With Go 1.18 beta 1
What operating system and processor architecture are you using (
go env
)?go env
OutputThe situation is reproducible with Go Playground on develop.
What did you do?
Trying out union interface types. The following program does not compile:
Go Play link
However, when I add another type
A3 [3]uint64
, then compiles and runs:Go Play link
What did you expect to see?
Nothing
What did you see instead?
./prog.go:19:7: [2]uint64 does not implement I[A2] (missing method Get)
The text was updated successfully, but these errors were encountered: