]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: assert that builtin reports valid operand mode upon success
authorRobert Griesemer <gri@golang.org>
Wed, 17 May 2023 00:24:16 +0000 (17:24 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 18 May 2023 18:39:32 +0000 (18:39 +0000)
Fix a case where x.mode == invalid was returned despite builtin
returning true.

Change-Id: Iae9c18aac16bcbadc3530d341b380e05c8743fcc
Reviewed-on: https://go-review.googlesource.com/c/go/+/495299
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/types2/builtins.go
src/go/types/builtins.go

index 63b62a66d2090291585ff037caf7699dc3f1dd55..de74da0bac53c38000c491395038d9768baff8ea 100644 (file)
@@ -200,12 +200,15 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                        }
                }
 
-               if mode == invalid && under(x.typ) != Typ[Invalid] {
-                       code := InvalidCap
-                       if id == _Len {
-                               code = InvalidLen
+               if mode == invalid {
+                       // avoid error if underlying type is invalid
+                       if under(x.typ) != Typ[Invalid] {
+                               code := InvalidCap
+                               if id == _Len {
+                                       code = InvalidLen
+                               }
+                               check.errorf(x, code, invalidArg+"%s for %s", x, bin.name)
                        }
-                       check.errorf(x, code, invalidArg+"%s for %s", x, bin.name)
                        return
                }
 
@@ -850,6 +853,7 @@ func (check *Checker) builtin(x *operand, call *syntax.CallExpr, id builtinId) (
                unreachable()
        }
 
+       assert(x.mode != invalid)
        return true
 }
 
index 63a59262dfc1a0adcaf7aa8900ce523468e26fa6..64d34e51cba542bc80cb949794979f09aca24ab6 100644 (file)
@@ -201,12 +201,15 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                        }
                }
 
-               if mode == invalid && under(x.typ) != Typ[Invalid] {
-                       code := InvalidCap
-                       if id == _Len {
-                               code = InvalidLen
+               if mode == invalid {
+                       // avoid error if underlying type is invalid
+                       if under(x.typ) != Typ[Invalid] {
+                               code := InvalidCap
+                               if id == _Len {
+                                       code = InvalidLen
+                               }
+                               check.errorf(x, code, invalidArg+"%s for %s", x, bin.name)
                        }
-                       check.errorf(x, code, invalidArg+"%s for %s", x, bin.name)
                        return
                }
 
@@ -851,6 +854,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b
                unreachable()
        }
 
+       assert(x.mode != invalid)
        return true
 }