]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: make built-in to accept type sets with single underlying types
authorRobert Findley <rfindley@google.com>
Fri, 29 Oct 2021 21:47:32 +0000 (17:47 -0400)
committerRobert Findley <rfindley@google.com>
Fri, 29 Oct 2021 22:27:26 +0000 (22:27 +0000)
This is a straightforward port of CL 357776 to go/types.

Change-Id: I64220840a01f57cd7955f7d956b9aa8227473b46
Reviewed-on: https://go-review.googlesource.com/c/go/+/359874
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/testdata/check/builtins.go2

index 29a8339f3ec6917993af9dfbe11d2c7c95c05f5b..de7d7e6b5fe53f7d895a4bb79a89cc1dbbb63292 100644 (file)
@@ -469,13 +469,13 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                }
 
                var min int // minimum number of arguments
-               switch optype(T).(type) {
+               switch singleUnder(T).(type) {
                case *Slice:
                        min = 2
                case *Map, *Chan:
                        min = 1
-               case *top:
-                       check.invalidArg(arg0, _InvalidMake, "cannot make %s; type parameter has no structural type", arg0)
+               case nil:
+                       check.errorf(arg0, _InvalidMake, "cannot make %s; type set has no single underlying type", arg0)
                        return
                default:
                        check.invalidArg(arg0, _InvalidMake, "cannot make %s; type must be slice, map, or channel", arg0)
index f9b6ec792615a43a9d4ace78e3238d53492257d1..7cca6fd7142d2b0bbc5675bba269f2e84e62d33d 100644 (file)
@@ -127,15 +127,18 @@ func _[T M4[K, V], K comparable, V any](m T) {
 
 // make
 
+type myChan chan int
+
 func _[
-       S1 interface{ []int },
-       S2 interface{ []int | chan int },
+       S1 ~[]int,
+       S2 ~[]int | ~chan int,
 
-       M1 interface{ map[string]int },
-       M2 interface{ map[string]int | chan int },
+       M1 ~map[string]int,
+       M2 ~map[string]int | ~chan int,
 
-       C1 interface{ chan int },
-       C2 interface{ chan int | chan string },
+       C1 ~chan int,
+       C2 ~chan int | ~chan string,
+       C3 chan int | myChan, // single underlying type
 ]() {
        type S0 []int
        _ = make([]int, 10)
@@ -145,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 structural type */ , 10)
+       _ = make(S2 /* ERROR cannot make .* no single underlying type */ , 10)
 
        type M0 map[string]int
        _ = make(map[string]int)
@@ -153,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 structural type */ )
+       _ = make(M2 /* ERROR cannot make .* no single underlying type */ )
 
        type C0 chan int
        _ = make(chan int)
@@ -161,7 +164,8 @@ func _[
        _ = make(C1)
        _ = make(C1, 10)
        _ = make/* ERROR expects 1 or 2 arguments */(C1, 10, 20)
-       _ = make(C2 /* ERROR cannot make .* no structural type */ )
+       _ = make(C2 /* ERROR cannot make .* no single underlying type */ )
+       _ = make(C3)
 }
 
 // unsafe.Alignof