-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: compilation results for generic types are affected by the filename #51048
Comments
Can you please try with the latest Go master version? This bug might have been fixed in the week since beta2 came out. Note that you'll need to change the import of the |
@mvdan Thanks for your reply quickly. I used
and replaced |
Ah, could you please push to your repo so we can also reproduce with master? |
Okay, it's there now |
The problem is fixed if you change
to
or
As the error message indicates, Robert/Rob: Things do in fact work if foo.go is renamed to hello.go. Also, we are not complaining about the use of |
It looks like an ordering problem (hence the dependence of the filename, the sources are processed by the type checker in filename-sorted order for deterministic behavior). Simpler reproducer: package p
// func f[T int]() {} // using this f doesn't produce the error
func _[T int]() {
_ = f[T] // ERROR T does not implement int (int is not an interface)
}
func f[T int]() {} // using this f produces the error |
Change https://go.dev/cl/383834 mentions this issue: |
@griesemer Thanks for your work. Is complaining about mistakes to be expected? Because I find it works well everywhere else except complaining |
@sxyazi I'm not sure I understand: what do you mean with "except complaining"? Do you mean that compiler is complaining with errors? With respect to this issue: this was a real bug in the compiler; thanks for bringing it up to our attention. I believe it should be fixed with the above CL. (And yes, if you find more cases that you think should work but don't, please file an issue.) |
@griesemer OK, I see. Thanks for your work again. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, it can be reproduced in the latest beta version. The minimal reproducible code I put at https://github.com/sxyazi/awesomeProject
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I executed
go test
, but it got an error. When I changed the file name fromfoo.go
tohello.go
, it worked correctly again. I suspect it has something to do with the compilation order of the filenames.What did you expect to see?
Pass the test correctly
What did you see instead?
The text was updated successfully, but these errors were encountered: