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 <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>
This commit is contained in:
Robert Griesemer 2023-05-18 20:06:42 -07:00 committed by Gopher Robot
parent a3e90dc377
commit ade3f3f5ef
2 changed files with 14 additions and 42 deletions

View 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 {

View 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 {