Navigation Menu

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

Closed
danscales opened this issue Feb 24, 2022 · 4 comments
Closed

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

danscales opened this issue Feb 24, 2022 · 4 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@danscales
Copy link
Contributor

Originally posted by @mpx in #51232 (comment)

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

From

package boom

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

func (f *Foo[T]) boom() {}

..at least, the call chain is more or less the same compared to @dr2chase's example:

[..]
panic({0xcaba20, 0x1311df0})
        src/runtime/panic.go:838 +0x207
cmd/compile/internal/types.(*Type).IsImplicit(0xc000648690?)
        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
cmd/compile/internal/noder.WriteExports(0xc000628010)
        src/cmd/compile/internal/noder/export.go:40 +0x7a
cmd/compile/internal/gc.dumpCompilerObj(0xc000628010?)
        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
cmd/compile/internal/gc.dumpobj()
        src/cmd/compile/internal/gc/obj.go:44 +0x36
cmd/compile/internal/gc.Main(0xd52330)
        src/cmd/compile/internal/gc/main.go:330 +0x11bc
main.main()
        src/cmd/compile/main.go:55 +0xdd
@danscales
Copy link
Contributor Author

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
@findleyr
Copy link
Contributor

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
@griesemer
Copy link
Contributor

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.

@gopherbot
Copy link

Change https://go.dev/cl/387836 mentions this issue: types2: method recv type parameter count must match base type parameter count

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 3, 2022
@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants