1
0
mirror of https://github.com/golang/go synced 2024-11-17 13:25:15 -07:00

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 <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2023-03-22 16:28:05 -07:00 committed by Gopher Robot
parent 8c5e8a38df
commit a933d06271
2 changed files with 20 additions and 38 deletions

View File

@ -129,15 +129,17 @@ func (check *Checker) initConst(lhs *Const, x *operand) {
lhs.val = x.val 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 x.mode == invalid || lhs.typ == Typ[Invalid] {
if lhs.typ == nil { if lhs.typ == nil {
lhs.typ = Typ[Invalid] 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 { if lhs.typ == nil {
typ := x.typ typ := x.typ
if isUntyped(typ) { if isUntyped(typ) {
@ -145,7 +147,7 @@ func (check *Checker) initVar(lhs *Var, x *operand, context string) Type {
if typ == Typ[UntypedNil] { if typ == Typ[UntypedNil] {
check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context) check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context)
lhs.typ = Typ[Invalid] lhs.typ = Typ[Invalid]
return nil return
} }
typ = Default(typ) typ = Default(typ)
} }
@ -153,11 +155,6 @@ func (check *Checker) initVar(lhs *Var, x *operand, context string) Type {
} }
check.assignment(x, lhs.typ, context) 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. // 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 return x.typ
} }
// assignVar checks the assignment lhs = x and returns the type of x. // assignVar checks the assignment lhs = x.
// If the assignment is invalid, the result is nil. func (check *Checker) assignVar(lhs syntax.Expr, x *operand) {
func (check *Checker) assignVar(lhs syntax.Expr, x *operand) Type {
if x.mode == invalid { if x.mode == invalid {
check.useLHS(lhs) check.useLHS(lhs)
return nil return
} }
T := check.lhsVar(lhs) // nil if lhs is _ T := check.lhsVar(lhs) // nil if lhs is _
if T == Typ[Invalid] { if T == Typ[Invalid] {
return nil return
} }
context := "assignment" context := "assignment"
@ -239,11 +235,6 @@ func (check *Checker) assignVar(lhs syntax.Expr, x *operand) Type {
context = "assignment to _ identifier" context = "assignment to _ identifier"
} }
check.assignment(x, T, context) check.assignment(x, T, context)
if x.mode == invalid {
return nil
}
return x.typ
} }
// operandTypes returns the list of types for the given operands. // operandTypes returns the list of types for the given operands.

View File

@ -127,15 +127,17 @@ func (check *Checker) initConst(lhs *Const, x *operand) {
lhs.val = x.val 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 x.mode == invalid || lhs.typ == Typ[Invalid] {
if lhs.typ == nil { if lhs.typ == nil {
lhs.typ = Typ[Invalid] 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 { if lhs.typ == nil {
typ := x.typ typ := x.typ
if isUntyped(typ) { if isUntyped(typ) {
@ -143,7 +145,7 @@ func (check *Checker) initVar(lhs *Var, x *operand, context string) Type {
if typ == Typ[UntypedNil] { if typ == Typ[UntypedNil] {
check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context) check.errorf(x, UntypedNilUse, "use of untyped nil in %s", context)
lhs.typ = Typ[Invalid] lhs.typ = Typ[Invalid]
return nil return
} }
typ = Default(typ) typ = Default(typ)
} }
@ -151,11 +153,6 @@ func (check *Checker) initVar(lhs *Var, x *operand, context string) Type {
} }
check.assignment(x, lhs.typ, context) 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. // 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 return x.typ
} }
// assignVar checks the assignment lhs = x and returns the type of x. // assignVar checks the assignment lhs = x.
// If the assignment is invalid, the result is nil. func (check *Checker) assignVar(lhs ast.Expr, x *operand) {
func (check *Checker) assignVar(lhs ast.Expr, x *operand) Type {
if x.mode == invalid { if x.mode == invalid {
check.useLHS(lhs) check.useLHS(lhs)
return nil return
} }
T := check.lhsVar(lhs) // nil if lhs is _ T := check.lhsVar(lhs) // nil if lhs is _
if T == Typ[Invalid] { if T == Typ[Invalid] {
return nil return
} }
context := "assignment" context := "assignment"
@ -237,11 +233,6 @@ func (check *Checker) assignVar(lhs ast.Expr, x *operand) Type {
context = "assignment to _ identifier" context = "assignment to _ identifier"
} }
check.assignment(x, T, context) check.assignment(x, T, context)
if x.mode == invalid {
return nil
}
return x.typ
} }
// operandTypes returns the list of types for the given operands. // operandTypes returns the list of types for the given operands.