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: obscure error messages for large constants #6648

Closed
gopherbot opened this issue Oct 23, 2013 · 6 comments
Closed

cmd/compile: obscure error messages for large constants #6648

gopherbot opened this issue Oct 23, 2013 · 6 comments

Comments

@gopherbot
Copy link

by borman@google.com:

Issue filed on suggestion of Ian

What steps will reproduce the problem?

Build the following package:

package b

var f = []float64 {
    47634102635436893179040485073748265163400240214004076398607741693502376385799646303105256699577209032590132615988260237052123652332890095616,
    12438414054641300055918190849808704283732243800785472203727097932000687811897290487171609691949473988773572358313712866199772466321053448142848,
}

What is the expected output?

A more meaningful error message (ideally no message, theoretically it should compile)
Appending a .0 to both constants results in the code compiling correctly.

What do you see instead?

The first element generates the messages:
./b.go:4: constant addition overflow
./b.go:4: overflow in constant

The second element generates the messages:
./b.go:5: constant multiplication overflow
./b.go:5: overflow in constant

If the first element is commented out the second element generates:
./b.go:5: ovf in mpaddxx
./b.go:5: constant multiplication overflow
./b.go:5: overflow in constant


Which compiler are you using (5g, 6g, 8g, gccgo)?
standard compiler, 6g

Which operating system are you using?
Mac OSX 10.8.5

Which version are you using?  (run 'go version')
go version go1.2rc2 darwin/amd64


Please provide any additional information below.

The first constant is 2^464, the second is 92!  Both of these values can be represented
in a float64 without loss of precision.
@rsc
Copy link
Contributor

rsc commented Oct 23, 2013

Comment 1:

We should make the error message better.
That said, the compiler is not required to handle this case.
Those are integers, not floating-point numbers, and the compiler is only required to
handle integers up to 2^128 (2x the precision of the largest run-time int type).

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 3:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 4:

Labels changed: added repo-main.

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title cmd/gc: obscure error messages for large constants cmd/compile: obscure error messages for large constants Jun 8, 2015
@odeke-em
Copy link
Member

I don't think this issue exists anymore at least on go1.6 given program https://play.golang.org/p/zxKzI4HJFz or inlined

package main

import (
    "fmt"
    "runtime"
)

var f = []float64{
    47634102635436893179040485073748265163400240214004076398607741693502376385799646303105256699577209032590132615988260237052123652332890095616,
    12438414054641300055918190849808704283732243800785472203727097932000687811897290487171609691949473988773572358313712866199772466321053448142848,
}

func main() {
    fmt.Printf("Version: %s\n[0]=%f [1]=%f\n", runtime.Version(), f[0], f[1])
}
$ go run main.go
Version: devel +c80e0d3 Wed Jul 27 05:43:36 2016 +0000
[0]=47634102635436893179040485073748265163400240214004076398607741693502376385799646303105256699577209032590132615988260237052123652332890095616.000000 [1]=12438414054641300055918190849808704283732243800785472203727097932000687811897290487171609691949473988773572358313712866199772466321053448142848.000000

When I upgrade to a larger constant to make it fail to compile, I get an improved error message given program https://play.golang.org/p/TMQxSJdr85

package main

import (
    "fmt"
    "runtime"
)

var f = []float64{
    47634102635436893171818181818181818818181818181818273737379040485073748265163400240214004076398607741693502376385799646303105256699577209032590132615988260237052123652332890095616,
    12438414054641300055918190849808704283732243800785472203727097932000687811897290487171609691949473988773572358313712866199772466321053448142848,
}

func main() {
    fmt.Printf("Version: %s\n[0]=%f [1]=%f\n", runtime.Version(), f[0], f[1])
}
$ go run main.go
# command-line-arguments
./TMQxSJdr85.go:9: constant too large: 47634102635436893171818181818181818818181818181818273737379040485073748265163400240214004076398607741693502376385799646303105256699577209032590132615988260237052123652332890095616
./TMQxSJdr85.go:9: overflow in constant
./TMQxSJdr85.go:9: constant Inf overflows float64

It seems like this issue was fixed by commit ed1a5e5 and CL https://go-review.googlesource.com/#/c/19962 by @griesemer.

@bradfitz
Copy link
Contributor

Thanks for investigating, @odeke-em.

@golang golang locked and limited conversation to collaborators Jul 27, 2017
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

4 participants