1
0
mirror of https://github.com/golang/go synced 2024-09-29 12:14:28 -06:00

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 <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>
This commit is contained in:
Matthew Dempsky 2022-05-02 17:36:04 -07:00
parent 53647a1994
commit 115c3bfad5

View 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])