]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/typecheck: avoid use of Name.Ntype for assignments
authorMatthew Dempsky <mdempsky@google.com>
Tue, 3 May 2022 00:36:04 +0000 (17:36 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 5 May 2022 18:48:08 +0000 (18:48 +0000)
Prep refactoring for the next CL, which removes Name.Ntype
entirely. Pulled out separately because this logic is a little subtle,
so this should be easier to bisect in case there's something I'm
missing here.

Change-Id: I4ffec6ee62fcd036582e8d2c963edcbd8bac184f
Reviewed-on: https://go-review.googlesource.com/c/go/+/403837
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>

src/cmd/compile/internal/typecheck/stmt.go

index 60bac77d19c2f63055e727290eb8a392b003d4d7..370e3248742654e10be68a9a4f2cd8e67061f820 100644 (file)
@@ -127,12 +127,9 @@ func assign(stmt ir.Node, lhs, rhs []ir.Node) {
 
        checkLHS := func(i int, typ *types.Type) {
                lhs[i] = Resolve(lhs[i])
-               if n := lhs[i]; typ != nil && ir.DeclaredBy(n, stmt) && n.Name().Ntype == nil {
-                       if typ.Kind() != types.TNIL {
-                               n.SetType(defaultType(typ))
-                       } else {
-                               base.Errorf("use of untyped nil")
-                       }
+               if n := lhs[i]; typ != nil && ir.DeclaredBy(n, stmt) && n.Type() == nil {
+                       base.Assertf(typ.Kind() == types.TNIL, "unexpected untyped nil")
+                       n.SetType(defaultType(typ))
                }
                if lhs[i].Typecheck() == 0 {
                        lhs[i] = AssignExpr(lhs[i])