From a933d06271f6ce42cf56edb012cc6361e6551f5e Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 22 Mar 2023 16:28:05 -0700 Subject: [PATCH] go/types, types2: remove return values from Checker.assignVar/initVar Not needed anymore. Change-Id: I5229d556ba1625f53b9fa23b496c17138a92fc3e Reviewed-on: https://go-review.googlesource.com/c/go/+/478717 Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Gopher Robot Reviewed-by: Robert Findley Auto-Submit: Robert Griesemer --- .../compile/internal/types2/assignments.go | 29 +++++++------------ src/go/types/assignments.go | 29 +++++++------------ 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/cmd/compile/internal/types2/assignments.go b/src/cmd/compile/internal/types2/assignments.go index 5436c46bf14..74987ece01c 100644 --- a/src/cmd/compile/internal/types2/assignments.go +++ b/src/cmd/compile/internal/types2/assignments.go @@ -129,15 +129,17 @@ func (check *Checker) initConst(lhs *Const, x *operand) { lhs.val = x.val } -func (check *Checker) initVar(lhs *Var, x *operand, context string) Type { +// initVar checks the initialization lhs = x in a variable declaration. +// If lhs doesn't have a type yet, it is given the type of x, +// or Typ[Invalid] in case of an error. +func (check *Checker) initVar(lhs *Var, x *operand, context string) { if x.mode == invalid || lhs.typ == Typ[Invalid] { if lhs.typ == nil { lhs.typ = Typ[Invalid] } - return nil } - // If the lhs doesn't have a type yet, use the type of x. + // If lhs doesn't have a type yet, use the type of x. if lhs.typ == nil { typ := x.typ if isUntyped(typ) { @@ -145,7 +147,7 @@ func (check *Checker) initVar(lhs *Var, x *operand, context string) Type { if typ == Typ[UntypedNil] { check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context) lhs.typ = Typ[Invalid] - return nil + return } typ = Default(typ) } @@ -153,11 +155,6 @@ func (check *Checker) initVar(lhs *Var, x *operand, context string) Type { } check.assignment(x, lhs.typ, context) - if x.mode == invalid { - return nil - } - - return x.typ } // lhsVar checks a lhs variable in an assignment and returns its type. @@ -221,17 +218,16 @@ func (check *Checker) lhsVar(lhs syntax.Expr) Type { return x.typ } -// 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 { +// assignVar checks the assignment lhs = x. +func (check *Checker) assignVar(lhs syntax.Expr, x *operand) { if x.mode == invalid { check.useLHS(lhs) - return nil + return } T := check.lhsVar(lhs) // nil if lhs is _ if T == Typ[Invalid] { - return nil + return } context := "assignment" @@ -239,11 +235,6 @@ func (check *Checker) assignVar(lhs syntax.Expr, x *operand) Type { context = "assignment to _ identifier" } check.assignment(x, T, context) - if x.mode == invalid { - return nil - } - - return x.typ } // operandTypes returns the list of types for the given operands. diff --git a/src/go/types/assignments.go b/src/go/types/assignments.go index 84b45f14031..fdf5a4b24c5 100644 --- a/src/go/types/assignments.go +++ b/src/go/types/assignments.go @@ -127,15 +127,17 @@ func (check *Checker) initConst(lhs *Const, x *operand) { lhs.val = x.val } -func (check *Checker) initVar(lhs *Var, x *operand, context string) Type { +// initVar checks the initialization lhs = x in a variable declaration. +// If lhs doesn't have a type yet, it is given the type of x, +// or Typ[Invalid] in case of an error. +func (check *Checker) initVar(lhs *Var, x *operand, context string) { if x.mode == invalid || lhs.typ == Typ[Invalid] { if lhs.typ == nil { lhs.typ = Typ[Invalid] } - return nil } - // If the lhs doesn't have a type yet, use the type of x. + // If lhs doesn't have a type yet, use the type of x. if lhs.typ == nil { typ := x.typ if isUntyped(typ) { @@ -143,7 +145,7 @@ func (check *Checker) initVar(lhs *Var, x *operand, context string) Type { if typ == Typ[UntypedNil] { check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context) lhs.typ = Typ[Invalid] - return nil + return } typ = Default(typ) } @@ -151,11 +153,6 @@ func (check *Checker) initVar(lhs *Var, x *operand, context string) Type { } check.assignment(x, lhs.typ, context) - if x.mode == invalid { - return nil - } - - return x.typ } // lhsVar checks a lhs variable in an assignment and returns its type. @@ -219,17 +216,16 @@ func (check *Checker) lhsVar(lhs ast.Expr) Type { return x.typ } -// 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 { +// assignVar checks the assignment lhs = x. +func (check *Checker) assignVar(lhs ast.Expr, x *operand) { if x.mode == invalid { check.useLHS(lhs) - return nil + return } T := check.lhsVar(lhs) // nil if lhs is _ if T == Typ[Invalid] { - return nil + return } context := "assignment" @@ -237,11 +233,6 @@ func (check *Checker) assignVar(lhs ast.Expr, x *operand) Type { context = "assignment to _ identifier" } check.assignment(x, T, context) - if x.mode == invalid { - return nil - } - - return x.typ } // operandTypes returns the list of types for the given operands.