]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: type-check built-ins even if there's a version error
authorRobert Griesemer <gri@golang.org>
Fri, 19 May 2023 03:06:42 +0000 (20:06 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 19 May 2023 13:42:46 +0000 (13:42 +0000)
There is no harm in continuing type-checking a built-in even if there
is a version error.

Change-Id: I161abd904a26075694c26639e247a17126947fcd
Reviewed-on: https://go-review.googlesource.com/c/go/+/496415
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/builtins.go
src/go/types/builtins.go

index e8c0859fa0325f27a642cd5aec202224ae49329d..0d1b9ed5e55e43795e1acd8ec83f0c9fbf1a7d29 100644 (file)
@@ -227,9 +227,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
        case _Clear:
                // clear(m)
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_21, "clear") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_21, "clear")
 
                if !underIs(x.typ, func(u Type) bool {
                        switch u.(type) {
@@ -536,9 +534,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
        case _Max, _Min:
                // max(x, ...)
                // min(x, ...)
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_21, bin.name) {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_21, bin.name)
 
                op := token.LSS
                if id == _Max {
@@ -659,9 +655,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
        case _Add:
                // unsafe.Add(ptr unsafe.Pointer, len IntegerType) unsafe.Pointer
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Add") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Add")
 
                check.assignment(x, Typ[UnsafePointer], "argument to unsafe.Add")
                if x.mode == invalid {
@@ -793,9 +787,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
        case _Slice:
                // unsafe.Slice(ptr *T, len IntegerType) []T
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Slice") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Slice")
 
                ptr, _ := under(x.typ).(*Pointer) // TODO(gri) should this be coreType rather than under?
                if ptr == nil {
@@ -816,9 +808,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
        case _SliceData:
                // unsafe.SliceData(slice []T) *T
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.SliceData") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.SliceData")
 
                slice, _ := under(x.typ).(*Slice) // TODO(gri) should this be coreType rather than under?
                if slice == nil {
@@ -834,9 +824,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
        case _String:
                // unsafe.String(ptr *byte, len IntegerType) string
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.String") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.String")
 
                check.assignment(x, NewPointer(universeByte), "argument to unsafe.String")
                if x.mode == invalid {
@@ -856,9 +844,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
 
        case _StringData:
                // unsafe.StringData(str string) *byte
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.StringData") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.StringData")
 
                check.assignment(x, Typ[String], "argument to unsafe.StringData")
                if x.mode == invalid {
index d40d8d77cc375334742325a7a344f0a3f830c2a2..85449338407cf469f658e0159b271903a5d9301c 100644 (file)
@@ -226,9 +226,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
        case _Clear:
                // clear(m)
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_21, "clear") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_21, "clear")
 
                if !underIs(x.typ, func(u Type) bool {
                        switch u.(type) {
@@ -535,9 +533,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
        case _Max, _Min:
                // max(x, ...)
                // min(x, ...)
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_21, bin.name) {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_21, bin.name)
 
                op := token.LSS
                if id == _Max {
@@ -658,9 +654,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
        case _Add:
                // unsafe.Add(ptr unsafe.Pointer, len IntegerType) unsafe.Pointer
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Add") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Add")
 
                check.assignment(x, Typ[UnsafePointer], "argument to unsafe.Add")
                if x.mode == invalid {
@@ -792,9 +786,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
        case _Slice:
                // unsafe.Slice(ptr *T, len IntegerType) []T
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Slice") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_17, "unsafe.Slice")
 
                ptr, _ := under(x.typ).(*Pointer) // TODO(gri) should this be coreType rather than under?
                if ptr == nil {
@@ -815,9 +807,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
        case _SliceData:
                // unsafe.SliceData(slice []T) *T
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.SliceData") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.SliceData")
 
                slice, _ := under(x.typ).(*Slice) // TODO(gri) should this be coreType rather than under?
                if slice == nil {
@@ -833,9 +823,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
        case _String:
                // unsafe.String(ptr *byte, len IntegerType) string
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.String") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.String")
 
                check.assignment(x, NewPointer(universeByte), "argument to unsafe.String")
                if x.mode == invalid {
@@ -855,9 +843,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
 
        case _StringData:
                // unsafe.StringData(str string) *byte
-               if !check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.StringData") {
-                       return
-               }
+               check.verifyVersionf(check.pkg, call.Fun, go1_20, "unsafe.StringData")
 
                check.assignment(x, Typ[String], "argument to unsafe.StringData")
                if x.mode == invalid {