]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "cmd/compile: improve errors for invalid conversions of consts"
authorMatthew Dempsky <mdempsky@google.com>
Fri, 6 Sep 2019 20:54:36 +0000 (20:54 +0000)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 6 Sep 2019 22:44:48 +0000 (22:44 +0000)
This reverts commit 2da9c3e0f99b72cf8f3bdca01b57e7a68a546c5b.

Reason for revert: while the new error messages are more informative,
they're not strictly correct. This CL also conflicts with CL 187657.

Change-Id: I1c36cf7e86c2f35ee83a4f98918ee38aa1f59965
Reviewed-on: https://go-review.googlesource.com/c/go/+/193977
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/const.go
test/fixedbugs/issue21979.go [deleted file]

index 569cab4390515472402a8a8c7902d5dde57c8386..c5b8d816c6c080126e7bbcb8118e97df672b8b9e 100644 (file)
@@ -413,20 +413,16 @@ func convlit1(n *Node, t *types.Type, explicit bool, reuse canReuseNode) *Node {
        return n
 
 bad:
-       reportErr := false
        if !n.Diag() {
-               reportErr = !t.Broke()
+               if !t.Broke() {
+                       yyerror("cannot convert %L to type %v", n, t)
+               }
                n.SetDiag(true)
        }
 
        if n.Type.IsUntyped() {
                n = defaultlitreuse(n, nil, reuse)
        }
-
-       if reportErr {
-               yyerror("cannot convert %L to type %v", n, t)
-       }
-
        return n
 }
 
diff --git a/test/fixedbugs/issue21979.go b/test/fixedbugs/issue21979.go
deleted file mode 100644 (file)
index ac7c88f..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-// errorcheck
-
-// Copyright 2019 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 p
-
-func f() {
-       // old error: "(type untyped string)"
-       _ = bool("") // ERROR "cannot convert .. \(type string\) to type bool"
-
-       // old error: "(type untyped number)"
-       _ = bool(1) // ERROR "cannot convert 1 \(type int\) to type bool"
-
-       // old error: "(type untyped number)"
-       _ = bool(1.0) // ERROR "cannot convert 1 \(type float64\) to type bool"
-
-       // old error: "(type untyped number)"
-       _ = bool(-4 + 2i) // ERROR "cannot convert -4 \+ 2i \(type complex128\) to type bool"
-
-       // old error: "(type untyped bool)"
-       _ = string(true) // ERROR "cannot convert true \(type bool\) to type string"
-
-       _ = string(-1)
-
-       // old error: "(type untyped number)"
-       _ = string(1.0) // ERROR "cannot convert 1 \(type float64\) to type string"
-
-       // old error: "(type untyped number)"
-       _ = string(-4 + 2i) // ERROR "cannot convert -4 \+ 2i \(type complex128\) to type string"
-
-       // old error: "(type untyped string)"
-       _ = int("") // ERROR "cannot convert .. \(type string\) to type int"
-
-       // old error: "(type untyped bool)"
-       _ = int(true) // ERROR "cannot convert true \(type bool\) to type int"
-
-       _ = int(-1)
-       _ = int(1)
-       _ = int(1.0)
-       _ = int(-4 + 2i) // ERROR "truncated to integer"
-
-       // old error: "(type untyped string)"
-       _ = uint("") // ERROR "cannot convert .. \(type string\) to type uint"
-
-       // old error: "(type untyped bool)"
-       _ = uint(true) // ERROR "cannot convert true \(type bool\) to type uint"
-
-       _ = uint(-1) // ERROR "constant -1 overflows uint"
-       _ = uint(1)
-       _ = uint(1.0)
-       _ = uint(-4 + 2i) // ERROR "constant -4 overflows uint" "truncated to integer"
-
-       // old error: "(type untyped string)"
-       _ = float64("") // ERROR "cannot convert .. \(type string\) to type float64"
-
-       // old error: "(type untyped bool)"
-       _ = float64(true) // ERROR "cannot convert true \(type bool\) to type float64"
-
-       _ = float64(-1)
-       _ = float64(1)
-       _ = float64(1.0)
-       _ = float64(-4 + 2i) // ERROR "truncated to real"
-
-       // old error: "(type untyped string)"
-       _ = complex128("") // ERROR "cannot convert .. \(type string\) to type complex128"
-
-       // old error: "(type untyped bool)"
-       _ = complex128(true) // ERROR "cannot convert true \(type bool\) to type complex128"
-
-       _ = complex128(-1)
-       _ = complex128(1)
-       _ = complex128(1.0)
-}