]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: remove return values from Checker.assignVar/initVar
authorRobert Griesemer <gri@golang.org>
Wed, 22 Mar 2023 23:28:05 +0000 (16:28 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 28 Mar 2023 18:13:15 +0000 (18:13 +0000)
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>

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

index 5436c46bf149d81721004c4e14727129b66f7438..74987ece01ca2ccd6e484abf337767094394e2cd 100644 (file)
@@ -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.
index 84b45f140310351023e300993d14922d6e9f1f13..fdf5a4b24c5e21f24c22953ab0706591e6f0051e 100644 (file)
@@ -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.