]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: remove unnecessary tests for x.typ == Typ[Invalid]
authorRobert Griesemer <gri@golang.org>
Wed, 22 Mar 2023 21:04:43 +0000 (14:04 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 28 Mar 2023 14:28:36 +0000 (14:28 +0000)
In the worst case (x.mode != invalid but x.typ == Typ[Invalid]) we
may get unexpected additional errors; but we don't seem to have
any such situations, at least in the existing tests.

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

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

index afbb1186b5a6df7ae95ca3a1aa3d4b06214e9942..9b130b48e1aaaae98ef2208c0d8cb1e547df6e07 100644 (file)
@@ -99,7 +99,7 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
 }
 
 func (check *Checker) initConst(lhs *Const, x *operand) {
-       if x.mode == invalid || x.typ == Typ[Invalid] || lhs.typ == Typ[Invalid] {
+       if x.mode == invalid || lhs.typ == Typ[Invalid] {
                if lhs.typ == nil {
                        lhs.typ = Typ[Invalid]
                }
@@ -130,7 +130,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) {
 }
 
 func (check *Checker) initVar(lhs *Var, x *operand, context string) Type {
-       if x.mode == invalid || x.typ == Typ[Invalid] || lhs.typ == Typ[Invalid] {
+       if x.mode == invalid || lhs.typ == Typ[Invalid] {
                if lhs.typ == nil {
                        lhs.typ = Typ[Invalid]
                }
@@ -198,10 +198,6 @@ func (check *Checker) lhsVar(lhs syntax.Expr) Type {
                v.used = v_used // restore v.used
        }
 
-       if x.mode == invalid || x.typ == Typ[Invalid] {
-               return Typ[Invalid]
-       }
-
        // spec: "Each left-hand side operand must be addressable, a map index
        // expression, or the blank identifier. Operands may be parenthesized."
        switch x.mode {
@@ -228,7 +224,7 @@ func (check *Checker) lhsVar(lhs syntax.Expr) Type {
 // assignVar checks the assignment lhs = x and returns the type of x.
 // If the assignment is invalid, the result is nil.
 func (check *Checker) assignVar(lhs syntax.Expr, x *operand) Type {
-       if x.mode == invalid || x.typ == Typ[Invalid] {
+       if x.mode == invalid {
                check.useLHS(lhs)
                return nil
        }
index e1b22d16ad42468093d77f14a942de204d6a2068..9d6a1ef4ed33a6223c1a28c82681ffbc219a0362 100644 (file)
@@ -97,7 +97,7 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
 }
 
 func (check *Checker) initConst(lhs *Const, x *operand) {
-       if x.mode == invalid || x.typ == Typ[Invalid] || lhs.typ == Typ[Invalid] {
+       if x.mode == invalid || lhs.typ == Typ[Invalid] {
                if lhs.typ == nil {
                        lhs.typ = Typ[Invalid]
                }
@@ -128,7 +128,7 @@ func (check *Checker) initConst(lhs *Const, x *operand) {
 }
 
 func (check *Checker) initVar(lhs *Var, x *operand, context string) Type {
-       if x.mode == invalid || x.typ == Typ[Invalid] || lhs.typ == Typ[Invalid] {
+       if x.mode == invalid || lhs.typ == Typ[Invalid] {
                if lhs.typ == nil {
                        lhs.typ = Typ[Invalid]
                }
@@ -196,10 +196,6 @@ func (check *Checker) lhsVar(lhs ast.Expr) Type {
                v.used = v_used // restore v.used
        }
 
-       if x.mode == invalid || x.typ == Typ[Invalid] {
-               return Typ[Invalid]
-       }
-
        // spec: "Each left-hand side operand must be addressable, a map index
        // expression, or the blank identifier. Operands may be parenthesized."
        switch x.mode {
@@ -226,7 +222,7 @@ func (check *Checker) lhsVar(lhs ast.Expr) Type {
 // assignVar checks the assignment lhs = x and returns the type of x.
 // If the assignment is invalid, the result is nil.
 func (check *Checker) assignVar(lhs ast.Expr, x *operand) Type {
-       if x.mode == invalid || x.typ == Typ[Invalid] {
+       if x.mode == invalid {
                check.useLHS(lhs)
                return nil
        }