From 115c3bfad55809a27009f9ea6f95970ff94164f0 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 2 May 2022 17:36:04 -0700 Subject: [PATCH] cmd/compile/internal/typecheck: avoid use of Name.Ntype for assignments 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 TryBot-Result: Gopher Robot Reviewed-by: Cuong Manh Le Run-TryBot: Matthew Dempsky --- src/cmd/compile/internal/typecheck/stmt.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/typecheck/stmt.go b/src/cmd/compile/internal/typecheck/stmt.go index 60bac77d19..370e324874 100644 --- a/src/cmd/compile/internal/typecheck/stmt.go +++ b/src/cmd/compile/internal/typecheck/stmt.go @@ -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])