From 89ec17be9a28e07f59aaaa9acd1d26f80c55711f Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Wed, 20 Jan 2021 13:54:53 -0800 Subject: [PATCH] [dev.typeparams] cmd/compile: simplify how irgen handles qualified idents This CL moves qualified identifier handling into expr0 with other selector expressions, rather than as a completely separate special case handled up front. This has a few benefits: 1. It's marginally simpler/cleaner. 2. It allows extra checking for imported objects that they have the same type that types2 thought they had. 3. For imported, untyped constants, we now instead handle them with the "tv.Value != nil" case. In particular, this ensures that they've always already been coerced to the appropriate concrete type by types2. Change-Id: Ibf44ae6901db36aa5251f70934616e9fcbd1cbc5 Reviewed-on: https://go-review.googlesource.com/c/go/+/285053 Trust: Matthew Dempsky Trust: Robert Griesemer Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/noder/expr.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/internal/noder/expr.go b/src/cmd/compile/internal/noder/expr.go index fba6ad2e4b..d5177ead06 100644 --- a/src/cmd/compile/internal/noder/expr.go +++ b/src/cmd/compile/internal/noder/expr.go @@ -27,15 +27,6 @@ func (g *irgen) expr(expr syntax.Expr) ir.Node { return ir.BlankNode } - // TODO(mdempsky): Is there a better way to recognize and handle qualified identifiers? - if expr, ok := expr.(*syntax.SelectorExpr); ok { - if name, ok := expr.X.(*syntax.Name); ok { - if _, ok := g.info.Uses[name].(*types2.PkgName); ok { - return g.use(expr.Sel) - } - } - } - tv, ok := g.info.Types[expr] if !ok { base.FatalfAt(g.pos(expr), "missing type for %v (%T)", expr, expr) @@ -89,6 +80,13 @@ func (g *irgen) expr0(typ types2.Type, expr syntax.Expr) ir.Node { case *syntax.ParenExpr: return g.expr(expr.X) // skip parens; unneeded after parse+typecheck case *syntax.SelectorExpr: + // Qualified identifier. + if name, ok := expr.X.(*syntax.Name); ok { + if _, ok := g.info.Uses[name].(*types2.PkgName); ok { + return g.use(expr.Sel) + } + } + // TODO(mdempsky/danscales): Use g.info.Selections[expr] // to resolve field/method selection. See CL 280633. return ir.NewSelectorExpr(pos, ir.OXDOT, g.expr(expr.X), g.name(expr.Sel)) -- 2.50.0