-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: incorrect type error after "type int64 int32" #38882
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
type int64 int32
type int64 int32
I suppose we could deliberately insert the package name when referring to a package scope variable that has the same name as a predeclared identifier. That seems a bit strange, but I guess it's not a common case. |
@ianlancetaylor It makes sense that if fmt.Printf says the type is main.int64, then the compiler should also say that the type is main.int64. |
Well, no, those are two different contexts. The reflect package uses a package name in front of every type name (other than predeclared types) because otherwise it would be ambiguous. The compiler does not normally use a package name in front of type names defined in the package being compiled, because a compiler error message is clearly in the context of the package being compiled. |
@ianlancetaylor Go's type declarations are kind of unintuitive. Like take this example:
I opened up a similar issue regarding type declarations, but this time with pointer types: |
You're right, the compiler does generate two different types, both named |
Duplicate of #38893 |
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
I expect to see "
constant 100000000000 overflows main.int64
".Either that or the line "
type int64 int32
" shouldn't compile.What did you see instead?
I see "
constant 100000000000 overflows int64
". That's incorrect because 100000000000 does not overflow int64. It overflows main.int64. Those are two different types.The text was updated successfully, but these errors were encountered: