Skip to content

Commit 115c3bf

Browse files
committed
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cuong Manh Le <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]>
1 parent 53647a1 commit 115c3bf

File tree

1 file changed

+3
-6
lines changed
  • src/cmd/compile/internal/typecheck

1 file changed

+3
-6
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,9 @@ func assign(stmt ir.Node, lhs, rhs []ir.Node) {
127127

128128
checkLHS := func(i int, typ *types.Type) {
129129
lhs[i] = Resolve(lhs[i])
130-
if n := lhs[i]; typ != nil && ir.DeclaredBy(n, stmt) && n.Name().Ntype == nil {
131-
if typ.Kind() != types.TNIL {
132-
n.SetType(defaultType(typ))
133-
} else {
134-
base.Errorf("use of untyped nil")
135-
}
130+
if n := lhs[i]; typ != nil && ir.DeclaredBy(n, stmt) && n.Type() == nil {
131+
base.Assertf(typ.Kind() == types.TNIL, "unexpected untyped nil")
132+
n.SetType(defaultType(typ))
136133
}
137134
if lhs[i].Typecheck() == 0 {
138135
lhs[i] = AssignExpr(lhs[i])

0 commit comments

Comments
 (0)