From: Robert Griesemer Date: Fri, 19 May 2023 03:06:42 +0000 (-0700) Subject: go/types, types2: type-check built-ins even if there's a version error X-Git-Tag: go1.21rc1~429 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ade3f3f5efd1a4a95b0070930644b8961646ee02;p=gostls13.git go/types, types2: type-check built-ins even if there's a version error 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 Reviewed-by: Robert Griesemer Auto-Submit: Robert Griesemer Run-TryBot: Robert Griesemer Reviewed-by: Robert Findley --- diff --git a/src/cmd/compile/internal/types2/builtins.go b/src/cmd/compile/internal/types2/builtins.go index e8c0859fa0..0d1b9ed5e5 100644 --- a/src/cmd/compile/internal/types2/builtins.go +++ b/src/cmd/compile/internal/types2/builtins.go @@ -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 { diff --git a/src/go/types/builtins.go b/src/go/types/builtins.go index d40d8d77cc..8544933840 100644 --- a/src/go/types/builtins.go +++ b/src/go/types/builtins.go @@ -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 {