]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: refer to structural rather than single underlying type in errors
authorRobert Findley <rfindley@google.com>
Tue, 16 Nov 2021 03:33:22 +0000 (22:33 -0500)
committerRobert Findley <rfindley@google.com>
Tue, 16 Nov 2021 15:16:41 +0000 (15:16 +0000)
This is a port of CL 362997 from types2 to go/types. Some error
positions were adjusted in tests.

Change-Id: I6a932aee1a8d9bcbf4cd8c16a95bbb41b5c7e13f
Reviewed-on: https://go-review.googlesource.com/c/go/+/363990
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/builtins.go
src/go/types/index.go
src/go/types/stmt.go
src/go/types/testdata/check/builtins.go2
src/go/types/testdata/check/typeparams.go2

index 9b50403d7f85865bc9d14358e38c9b0c462c6b44..b767128367bc1c4794c958fc81bc26fabee02388 100644 (file)
@@ -479,7 +479,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                case *Map, *Chan:
                        min = 1
                case nil:
-                       check.errorf(arg0, _InvalidMake, "cannot make %s; type set has no single underlying type", arg0)
+                       check.errorf(arg0, _InvalidMake, "cannot make %s: no structural type", arg0)
                        return
                default:
                        check.invalidArg(arg0, _InvalidMake, "cannot make %s; type must be slice, map, or channel", arg0)
index 534b445e9e107792b60277fc62d786085e9efdb7..0284716277590d13153dd7777da0e35952808fbd 100644 (file)
@@ -213,7 +213,7 @@ func (check *Checker) sliceExpr(x *operand, e *ast.SliceExpr) {
        length := int64(-1) // valid if >= 0
        switch u := structuralType(x.typ).(type) {
        case nil:
-               check.errorf(x, _NonSliceableOperand, "cannot slice %s: type set has no single underlying type", x)
+               check.invalidOp(x, _NonSliceableOperand, "cannot slice %s: %s has no structural type", x, x.typ)
                x.mode = invalid
                return
 
index 3d4a20f80831c0f701f20e1cbb48800fe370e13a..e7514f19aec5cfdb5fbe369d2f7026e7107c2781 100644 (file)
@@ -832,12 +832,12 @@ func (check *Checker) stmt(ctxt stmtContext, s ast.Stmt) {
                // determine key/value types
                var key, val Type
                if x.mode != invalid {
-                       // Ranging over a type parameter is permitted if it has a single underlying type.
+                       // Ranging over a type parameter is permitted if it has a structural type.
                        var cause string
                        u := structuralType(x.typ)
                        switch t := u.(type) {
                        case nil:
-                               cause = "type set has no single underlying type"
+                               cause = check.sprintf("%s has no structural type", x.typ)
                        case *Chan:
                                if s.Value != nil {
                                        check.softErrorf(s.Value, _InvalidIterVar, "range over %s permits only one iteration variable", &x)
index 7cca6fd7142d2b0bbc5675bba269f2e84e62d33d..c1accff016a8a54b4a393085e872bf665deae1b9 100644 (file)
@@ -148,7 +148,7 @@ func _[
        _ = make /* ERROR expects 2 or 3 arguments */ (S1)
        _ = make(S1, 10, 20)
        _ = make /* ERROR expects 2 or 3 arguments */ (S1, 10, 20, 30)
-       _ = make(S2 /* ERROR cannot make .* no single underlying type */ , 10)
+       _ = make(S2 /* ERROR cannot make S2: no structural type */ , 10)
 
        type M0 map[string]int
        _ = make(map[string]int)
@@ -156,7 +156,7 @@ func _[
        _ = make(M1)
        _ = make(M1, 10)
        _ = make/* ERROR expects 1 or 2 arguments */(M1, 10, 20)
-       _ = make(M2 /* ERROR cannot make .* no single underlying type */ )
+       _ = make(M2 /* ERROR cannot make M2: no structural type */ )
 
        type C0 chan int
        _ = make(chan int)
@@ -164,7 +164,7 @@ func _[
        _ = make(C1)
        _ = make(C1, 10)
        _ = make/* ERROR expects 1 or 2 arguments */(C1, 10, 20)
-       _ = make(C2 /* ERROR cannot make .* no single underlying type */ )
+       _ = make(C2 /* ERROR cannot make C2: no structural type */ )
        _ = make(C3)
 }
 
index 09d478c4d75a046e65a2cc8db62b306c70e4848f..6bf303af905cf5b46eb1bc90cfcd1862f57989bc 100644 (file)
@@ -134,7 +134,7 @@ func _[T interface{ ~string }] (x T, i, j, k int) { var _ T = x /* ERROR 3-index
 type myByte1 []byte
 type myByte2 []byte
 func _[T interface{ []byte | myByte1 | myByte2 }] (x T, i, j, k int) { var _ T = x[i:j:k] }
-func _[T interface{ []byte | myByte1 | []int }] (x T, i, j, k int) { var _ T = x /* ERROR no single underlying type */ [i:j:k] }
+func _[T interface{ []byte | myByte1 | []int }] (x T, i, j, k int) { var _ T = x /* ERROR no structural type */ [i:j:k] }
 
 // len/cap built-ins
 
@@ -210,7 +210,7 @@ func _[
         for _, _ /* ERROR permits only one iteration variable */ = range c1 {}
 
         var c2 C2
-        for range c2 /* ERROR cannot range over c2.*no single underlying type */ {}
+        for range c2 /* ERROR cannot range over c2.*no structural type */ {}
 
         var c3 C3
         for range c3 /* ERROR receive from send-only channel */ {}
@@ -226,7 +226,7 @@ func _[
         for _, _ = range s1 {}
 
         var s2 S2
-        for range s2 /* ERROR cannot range over s2.*no single underlying type */ {}
+        for range s2 /* ERROR cannot range over s2.*no structural type */ {}
 
         var a0 []int
         for range a0 {}
@@ -239,7 +239,7 @@ func _[
         for _, _ = range a1 {}
 
         var a2 A2
-        for range a2 /* ERROR cannot range over a2.*no single underlying type */ {}
+        for range a2 /* ERROR cannot range over a2.*no structural type */ {}
 
         var p0 *[10]int
         for range p0 {}
@@ -252,7 +252,7 @@ func _[
         for _, _ = range p1 {}
 
         var p2 P2
-        for range p2 /* ERROR cannot range over p2.*no single underlying type */ {}
+        for range p2 /* ERROR cannot range over p2.*no structural type */ {}
 
         var m0 map[string]int
         for range m0 {}
@@ -265,7 +265,7 @@ func _[
         for _, _ = range m1 {}
 
         var m2 M2
-        for range m2 /* ERROR cannot range over m2.*no single underlying type */ {}
+        for range m2 /* ERROR cannot range over m2.*no structural type */ {}
 }
 
 // type inference checks