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: builtin print treat arguments differently from normal functions #49042
Comments
At tip, we get the correct errors (one at each line). |
@randall77 I think we should re-open this for discussion. The compiler typechecker has special case for @go101 At least, |
@cuonglm Here, by the spec, the default type of |
@cuonglm I'll reopen, but I'm not sure why. Do you have an example where tip misbehaves? |
It is okay before Go 1.14. |
I don't say tip misbehaves, but I mean the old typechecker have special case for int constant as argument to
@go101 No, |
package main
import "fmt"
const X = '\x61' // 'a'
const Y = 0x62
const A = Y - X
func main() {
fmt.Printf("%T \n", A << 30) // int32
}
|
@go101 |
Up through Go 1.17, the predeclared We can regard this as a bug fix, but I suspect that it may be an accident. In fact the code to use If we start reporting the error we may break existing working programs. We can do that on the argument that this behavior was never documented and is arguably buggy, but let's at least do it intentionally. |
@ianlancetaylor Yeah, the code you pointed out is for the old typchecker, at tip, we're using Also, here's the relevant part in old typechecker: go/src/cmd/compile/internal/typecheck/func.go Line 857 in 4d55072
|
The spec says:
and:
So arguably this change is ok. Also, I wouldn't so much call it an "accident" but a consequence of handling the arguments here no different from anywhere else. (I suspect it might be rather annoying to make the code accept the arguably incorrect argument, but I haven't tried yet). TBD. |
Filed proposal #49216 to decide if we can make this change. |
Per #49216 we will accept the correct behavior and document it in the release notes. If this ends up breaking a lot of code, we can re-open. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What did you do?
[Edit]: A simpler one:
What did you expect to see?
Same behavior.
What did you see instead?
Different behavior.
(Maybe this is not a bug, but it should be mentioned somewhere in docs.)
[Edit]: this has been broken since Go toolchain 1.14.
The text was updated successfully, but these errors were encountered: