-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
cmd/compile: build panic if there are same name Type and TypeAlias #31959
Comments
This looks like a compiler error because it does compile like this: https://play.golang.org/p/Jfrn1JdRnGG package main
import "fmt"
type A struct{}
func B() {
type A = map[string]map[string]interface{}
fmt.Println(A{})
}
func main() {
fmt.Println(A{})
B()
} The alias in the function correctly shadows the top level struct but only inside the function. |
I can run this code successful so I append two cases which correctly in the end of issues |
The problem is type alias typecheck always replace the original definition of the symbol, so the symbol is written to compiled file as alias, instead of original type. When a file import this compiled file, the import reader see the original type at line 3, but with wrong symbol metadata (which is alias), causing infinite loop to detect the right type for symbol, the compiler goes boom. I'm sending a CL to fix it. |
Change https://golang.org/cl/177378 mentions this issue: |
thanks all ! |
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
)?go env
OutputWhat did you do?
Give a type named "A" and a type alias named "A" in a function,
then import this package in other place
What did you expect to see?
go build success or failed with redefined message
What did you see instead?
go build panic
some useful info for yours
cases don't panic and can build success:
type A = xx
totype A xx
will build successthanks~
The text was updated successfully, but these errors were encountered: