Skip to content
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: types2 not giving error for missing method typeparam #51339

danscales opened this issue Feb 24, 2022 · 4 comments

cmd/compile: types2 not giving error for missing method typeparam #51339

danscales opened this issue Feb 24, 2022 · 4 comments


Copy link

@danscales danscales commented Feb 24, 2022

Originally posted by @mpx in #51232 (comment)

go version devel +c9fe126c8b Mon Feb 21 21:28:40 2022 +0000 linux/amd64


package boom

type Foo[T any, PT *T] struct{}

func (f *Foo[T]) boom() {} least, the call chain is more or less the same compared to @dr2chase's example:

panic({0xcaba20, 0x1311df0})
        src/runtime/panic.go:838 +0x207
        src/cmd/compile/internal/types/type.go:1907 +0x18
cmd/compile/internal/typecheck.(*iexporter).doDecl(0xc00063c000, 0xc00041a0d0)
        src/cmd/compile/internal/typecheck/iexport.go:568 +0x38d 
cmd/compile/internal/typecheck.WriteExports({0xe93080, 0xc00061a1b0}, 0x1)
        src/cmd/compile/internal/typecheck/iexport.go:334 +0x2f0
        src/cmd/compile/internal/noder/export.go:40 +0x7a
        src/cmd/compile/internal/gc/obj.go:107 +0x28
cmd/compile/internal/gc.dumpobj1({0x7fff5b4cc9ce, 0x23}, 0x3)
        src/cmd/compile/internal/gc/obj.go:63 +0x17b
        src/cmd/compile/internal/gc/obj.go:44 +0x36
        src/cmd/compile/internal/gc/main.go:330 +0x11bc
        src/cmd/compile/main.go:55 +0xdd
Copy link
Contributor Author

@danscales danscales commented Feb 24, 2022

@griesemer @findleyr

Here's a very simple case where types2 is not giving an error when a method is missing one of the required typeparams for its generic receiver type. This only appears to happen because the typeparam PT is expressed in terms of T (structural constraint). The error is properly reported if we change PT *T to PT any

@danscales danscales added this to the Go1.18 milestone Feb 24, 2022
Copy link

@findleyr findleyr commented Feb 24, 2022

This is due to constraint type inference at the receiver type expression.

See also #51233 -- these are not really related, but both suggest to me that type inference for type instances is too naive, and we (I) didn't give it enough thought.

@griesemer griesemer self-assigned this Feb 24, 2022
Copy link

@griesemer griesemer commented Feb 24, 2022

I don't think we should ever allow type inference at the receiver type expression. The spec is clear that we need to provide all type parameters in that case. When we do, the error goes away as far as I can tell.

Copy link

@gopherbot gopherbot commented Feb 24, 2022

Change mentions this issue: types2: method recv type parameter count must match base type parameter count

@dmitshur dmitshur added the NeedsFix label Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

5 participants