]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: print "nil" rather than "untyped nil"
authorRobert Griesemer <gri@golang.org>
Mon, 22 Nov 2021 21:53:21 +0000 (13:53 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 22 Nov 2021 23:51:43 +0000 (23:51 +0000)
When we have a typed nil, we already say so; thus it is sufficient
to use "nil" in all the other cases.

This is closer to (1.17) compiler behavior. In cases where the
1.17 compiler prints "untyped nil" (e.g., wrong uses of "copy"),
we already print a different message. We can do better in those
cases as well; will be addressed in a separate CL (see #49735).

Fixes #48852.

Change-Id: I9a7a72e0f99185b00f80040c5510a693b1ea80f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/366276
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/assignments.go
src/cmd/compile/internal/types2/operand.go
src/cmd/compile/internal/types2/testdata/check/stmt0.src
src/cmd/compile/internal/types2/testdata/fixedbugs/issue49296.go2
src/cmd/compile/internal/types2/testdata/spec/assignability.go2
test/fixedbugs/issue6004.go
test/fixedbugs/issue6402.go
test/fixedbugs/issue7223.go

index a3d32093d624075d6079edc73a92e9a54bdc3588..ac4f7b88a49821212d3115cf7bae8e79a6a20d98 100644 (file)
@@ -220,9 +220,6 @@ func (check *Checker) assignVar(lhs syntax.Expr, x *operand) Type {
                return nil
        case variable, mapindex:
                // ok
-       case nilvalue:
-               check.error(&z, "cannot assign to nil") // default would print "untyped nil"
-               return nil
        default:
                if sel, ok := z.expr.(*syntax.SelectorExpr); ok {
                        var op operand
index 6581d80323ba708c6be9105dc53bd236b84249ea..f6bd0291ece212a7f6b261883a7bd61a6d1004e7 100644 (file)
@@ -116,7 +116,7 @@ func operandString(x *operand, qf Qualifier) string {
                case nil, Typ[Invalid]:
                        return "nil (with invalid type)"
                case Typ[UntypedNil]:
-                       return "untyped nil"
+                       return "nil"
                default:
                        return fmt.Sprintf("nil (of type %s)", TypeString(x.typ, qf))
                }
index d744f2ba814d593f0df5fb200b069bef1ab45cae..353444f06880f78385536407604ca11bfbc61e89 100644 (file)
@@ -69,10 +69,10 @@ func assignments1() {
 
        // test cases for issue 5800
        var (
-               _ int = nil /* ERROR "untyped nil" */
-               _ [10]int = nil /* ERROR "untyped nil" */
+               _ int = nil /* ERROR "nil" */
+               _ [10]int = nil /* ERROR "nil" */
                _ []byte = nil
-               _ struct{} = nil /* ERROR "untyped nil" */
+               _ struct{} = nil /* ERROR "nil" */
                _ func() = nil
                _ map[int]string = nil
                _ chan int = nil
index 8f52acc8a4c3f8333622e77a584615d3c4078c4c..eaa8e4dc7d8ad6d33c582f79c89d903da03b8721 100644 (file)
@@ -9,7 +9,7 @@ func _[
         T1 []int,
         T2 ~float64 | ~complex128 | chan int,
 ]() {
-        _ = T0(nil /* ERROR cannot convert untyped nil to T0 */ )
+        _ = T0(nil /* ERROR cannot convert nil to T0 */ )
         _ = T1(1 /* ERROR cannot convert 1 .* to T1 */ )
         _ = T2(2 /* ERROR cannot convert 2 .* to T2 */ )
 }
index fb28358bbbca62202d08f69771b4f556b6acc0a6..507fe6d021f7ad37cae9cb33202fcc4be57787e9 100644 (file)
@@ -153,28 +153,28 @@ func _[
 
 // "x is the predeclared identifier nil and T is a pointer, function, slice, map, channel, or interface type"
 func _[TP Interface](X TP) {
-       b = nil // ERROR cannot use untyped nil
-       a = nil // ERROR cannot use untyped nil
+       b = nil // ERROR cannot use nil
+       a = nil // ERROR cannot use nil
        l = nil
-       s = nil // ERROR cannot use untyped nil
+       s = nil // ERROR cannot use nil
        p = nil
        f = nil
        i = nil
        m = nil
        c = nil
-       d = nil // ERROR cannot use untyped nil
+       d = nil // ERROR cannot use nil
 
-       B = nil // ERROR cannot use untyped nil
-       A = nil // ERROR cannot use untyped nil
+       B = nil // ERROR cannot use nil
+       A = nil // ERROR cannot use nil
        L = nil
-       S = nil // ERROR cannot use untyped nil
+       S = nil // ERROR cannot use nil
        P = nil
        F = nil
        I = nil
        M = nil
        C = nil
-       D = nil // ERROR cannot use untyped nil
-       X = nil // ERROR cannot use untyped nil
+       D = nil // ERROR cannot use nil
+       X = nil // ERROR cannot use nil
 }
 
 // "x is an untyped constant representable by a value of type T"
index 2b3dcd923d6a653935e087fd65777ee541c63ba5..99d6ab85ea5def02b1e3cac9b95d92c59cdb6d3f 100644 (file)
@@ -7,9 +7,8 @@
 package main
 
 func main() {
-       _ = nil // ERROR "use of untyped nil"
-       _, _ = nil, 1 // ERROR "use of untyped nil"
-       _, _ = 1, nil // ERROR "use of untyped nil"
-       _ = append(nil, 1, 2, 3) // ERROR "untyped nil"
+       _ = nil                  // ERROR "use of untyped nil"
+       _, _ = nil, 1            // ERROR "use of untyped nil"
+       _, _ = 1, nil            // ERROR "use of untyped nil"
+       _ = append(nil, 1, 2, 3) // ERROR "untyped nil|nil"
 }
-
index 39cb9ac3f06f94492f57b1c16d909038770e1d1b..9977027d183fefbe0c8bc022e1b8fd3b59308999 100644 (file)
@@ -9,5 +9,5 @@
 package p
 
 func f() uintptr {
-       return nil // ERROR "cannot use nil as type uintptr in return argument|incompatible type|cannot use untyped nil"
+       return nil // ERROR "cannot use nil as type uintptr in return argument|incompatible type|cannot use nil"
 }
index c78de287ff61f3988c54a9a1c8eeb0a103d7f0fc..129e20f49702279738e87c9ac716a28484e6599b 100644 (file)
@@ -7,14 +7,15 @@
 package main
 
 var bits1 uint = 10
+
 const bits2 uint = 10
 
 func main() {
        _ = make([]byte, 1<<bits1)
        _ = make([]byte, 1<<bits2)
-       _ = make([]byte, nil) // ERROR "non-integer.*len|untyped nil"
-       _ = make([]byte, nil, 2) // ERROR "non-integer.*len|untyped nil"
-       _ = make([]byte, 1, nil) // ERROR "non-integer.*cap|untyped nil"
-       _ = make([]byte, true) // ERROR "non-integer.*len|untyped bool"
-       _ = make([]byte, "abc") // ERROR "non-integer.*len|untyped string"
+       _ = make([]byte, nil)    // ERROR "non-integer.*len|nil"
+       _ = make([]byte, nil, 2) // ERROR "non-integer.*len|nil"
+       _ = make([]byte, 1, nil) // ERROR "non-integer.*cap|nil"
+       _ = make([]byte, true)   // ERROR "non-integer.*len|untyped bool"
+       _ = make([]byte, "abc")  // ERROR "non-integer.*len|untyped string"
 }