From 4c49d52439805c248f4a01d529b90b22e821b7d6 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 22 Mar 2023 14:04:43 -0700 Subject: [PATCH] go/types, types2: remove unnecessary tests for x.typ == Typ[Invalid] 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 Reviewed-by: Robert Griesemer Auto-Submit: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Gopher Robot --- src/cmd/compile/internal/types2/assignments.go | 10 +++------- src/go/types/assignments.go | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/cmd/compile/internal/types2/assignments.go b/src/cmd/compile/internal/types2/assignments.go index afbb1186b5..9b130b48e1 100644 --- a/src/cmd/compile/internal/types2/assignments.go +++ b/src/cmd/compile/internal/types2/assignments.go @@ -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 } diff --git a/src/go/types/assignments.go b/src/go/types/assignments.go index e1b22d16ad..9d6a1ef4ed 100644 --- a/src/go/types/assignments.go +++ b/src/go/types/assignments.go @@ -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 } -- 2.48.1