]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: better errors for float constants with large exponents
authorRobert Griesemer <gri@golang.org>
Mon, 8 May 2017 20:32:18 +0000 (13:32 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 8 May 2017 22:56:10 +0000 (22:56 +0000)
Also: Removed misleading comment.

Fixes #20232.

Change-Id: I0b141b1360ac53267b7ebfcec7a2e2a238f3f46c
Reviewed-on: https://go-review.googlesource.com/42930
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/mpfloat.go
src/go/types/stdlib_test.go
test/fixedbugs/issue20232.go [new file with mode: 0644]

index a3785a045c7381492a98f9cc87c0b8f3be8f9f38..8d7036ba192e48d4ebb7dab7983b6c2bc6c24934 100644 (file)
@@ -176,25 +176,14 @@ func (a *Mpflt) Neg() {
        }
 }
 
-//
-// floating point input
-// required syntax is [+-]d*[.]d*[e[+-]d*] or [+-]0xH*[e[+-]d*]
-//
 func (a *Mpflt) SetString(as string) {
        for len(as) > 0 && (as[0] == ' ' || as[0] == '\t') {
                as = as[1:]
        }
 
-       f, ok := a.Val.SetString(as)
-       if !ok {
-               // At the moment we lose precise error cause;
-               // the old code additionally distinguished between:
-               // - malformed hex constant
-               // - decimal point in hex constant
-               // - constant exponent out of range
-               // - decimal point and binary point in constant
-               // TODO(gri) use different conversion function or check separately
-               yyerror("malformed constant: %s", as)
+       f, _, err := a.Val.Parse(as, 10)
+       if err != nil {
+               yyerror("malformed constant: %s (%v)", as, err)
                a.Val.SetFloat64(0)
                return
        }
index ed09e4644be1090113eafc5db07e4e722c8c419d..4b6b1f0fad503f48fb6bde459a6216c447196632 100644 (file)
@@ -159,6 +159,7 @@ func TestStdFixed(t *testing.T) {
                "issue16369.go", // go/types handles this correctly - not an issue
                "issue18459.go", // go/types doesn't check validity of //go:xxx directives
                "issue18882.go", // go/types doesn't check validity of //go:xxx directives
+               "issue20232.go", // go/types handles larger constants than gc
        )
 }
 
diff --git a/test/fixedbugs/issue20232.go b/test/fixedbugs/issue20232.go
new file mode 100644 (file)
index 0000000..f91c749
--- /dev/null
@@ -0,0 +1,11 @@
+// errorcheck
+
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+const _ = 6e5518446744 // ERROR "malformed constant: 6e5518446744 \(exponent overflow\)"
+const _ = 1e-1000000000
+const _ = 1e+1000000000 // ERROR "constant too large"