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
Assignees
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Aug 30, 2019

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

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 30, 2019

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

This comment has been minimized.

Copy link
Contributor Author

@griesemer 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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Aug 30, 2019

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

@griesemer

This comment has been minimized.

Copy link
Contributor Author

@griesemer griesemer commented Aug 30, 2019

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

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 30, 2019

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"
      |                ^
@gopherbot gopherbot closed this in cdd2c26 Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.