-
Notifications
You must be signed in to change notification settings - Fork 18.1k
runtime: wrong type assertion result when using generic types #51700
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
Comments
Simplified version (playground): package main
func f[B any](b B) {
if b1, ok := any(b).(interface{ m1() }); ok {
panic(1)
_ = b1.(B) // <<< removing this type assertion makes this code work
}
if b2, ok := any(b).(interface{ m2() }); ok {
panic(2)
_ = b2.(B) // <<< removing this type assertion makes this code work
}
}
type S struct{}
func (S) m3() {}
func main() {
f(S{})
} Replacing the type parameter |
Test cases run correctly (i.e., exit quietly with success) with |
Tentatively marking release blocker. |
|
It seems to happen for any named type. E.g., instantiating |
@gopherbot Please open backport to 1.18. This appears to be incorrect code generation, so we should backport the fix when we have one. |
Backport issue(s) opened: #51738 (for 1.18). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Change https://go.dev/cl/399058 mentions this issue: |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?doesn't matter. It can reproduce on the go playground.
go env
OutputWhat did you do?
https://go.dev/play/p/A9VuqCpJ7r5
What did you expect to see?
As
S
does not have method nameM1
orM2
, it should not panic.What did you see instead?
Panic and output
iface1
. I also noticed that if I renameIFace2
toAFace2
, the result is panic and outputiface2
.The text was updated successfully, but these errors were encountered: