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: incorrect "cannot use .this" error when using _ for multiple type parameters in method declaration #50419
Comments
Thanks for the issue report! This is a problem in the main compiler (not the types2 typechecker). It happens when generating method wrappers. It looks like the use of |
Change https://golang.org/cl/375474 mentions this issue: |
Change https://golang.org/cl/375641 mentions this issue: |
Change https://golang.org/cl/379194 mentions this issue: |
In a method declaration "func (f *Foo[_, _]) String() string { ... }", the two blank typeparams have the same name, but our current design with types1 needs unique names for type params. Similarly, for export/import, we need unique names to keep the type params straight in generic types and connect the proper type param with the proper constraint. We make blank type params unique by changing them to $1, $2, etc in noder.typ0() via typecheck.TparamExportName(). We then revert $<num> back to _ during type2 import via typecheck.TparamName(). We similarly revert during gcimporter import. We don't need/want to revert in the types1 importer, since we want unique names for type params. Rob Findley has made a similar change to x/tools (and we tried to make the source code changes similar for the gcimporter and types2 importer changes). Fixes golang#50419 Change-Id: I855cc3d90d06bcf59541ed0c879e9a0e4ede45bb Reviewed-on: https://go-review.googlesource.com/c/go/+/379194 Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
N/A. Type parameters are not available in any other version that are currently available.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
I expected the code snippet above to build and run successfully.
What did you see instead?
Build error:
The text was updated successfully, but these errors were encountered: