Skip to content
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: invalid literal 0b.p produces 4 error messages #33961

Closed
griesemer opened this issue Aug 30, 2019 · 5 comments
Closed

cmd/compile: invalid literal 0b.p produces 4 error messages #33961

griesemer opened this issue Aug 30, 2019 · 5 comments
Milestone

Comments

@griesemer
Copy link
Contributor

Compiling

package p
const _ = 0b.p

produces 4 error messages:

x.go:2:13: invalid radix point in binary literal
x.go:2:14: binary literal has no digits
x.go:2:14: 'p' exponent requires hexadecimal mantissa
x.go:2:15: exponent has no digits

The first one would suffice.

@griesemer griesemer self-assigned this Aug 30, 2019
@griesemer griesemer added this to the Go1.14 milestone Aug 30, 2019
@ianlancetaylor
Copy link
Contributor

gccgo reports

foo.go:2:11: error: invalid numeric literal
    2 | const _ = 0b.p
      |           ^
foo.go:2:13: error: reference to field ‘p’ in object which has no fields or methods
    2 | const _ = 0b.p
      |             ^

@griesemer
Copy link
Contributor Author

griesemer commented Aug 30, 2019

@ianlancetaylor With Go 1.14, the number scanner takes the approach of a very much relaxed number syntax and so all of 0b.p is considered a (invalid) number. Not clear if that's better than what we had before - but it is certainly easy to lex. Anyway, this specific issue is trivial to fix and actually simplifies the code.

@gopherbot
Copy link

Change https://golang.org/cl/192499 mentions this issue: cmd/compile/internal/scanner: report at most one lexical error per token

@griesemer
Copy link
Contributor Author

@ianlancetaylor What does gccgo report for "\?\777\xax" ?

@ianlancetaylor
Copy link
Contributor

What does gccgo report for "?\777\xax" ?

foo.go:3:10: error: invalid character after ‘\’
    3 | var S = "\?\777\xax"
      |          ^
foo.go:3:12: error: invalid octal constant
    3 | var S = "\?\777\xax"
      |            ^
foo.go:3:16: error: invalid hex character
    3 | var S = "\?\777\xax"
      |                ^

@golang golang locked and limited conversation to collaborators Sep 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants