mirror of
https://github.com/golang/go
synced 2024-11-26 06:17:57 -07:00
[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 <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
fa01ade41e
commit
89ec17be9a
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user