[dev.unified] cmd/compile/internal/noder: stop handling type expressions as expressions

There are two places currently where we rely on type expressions as
generic expressions: the first argument to "make" and "new", and the
selectable operand within a method expression.

This CL makes that code responsible for handling the type expressions
directly. Longer term, this will be relevant to appropriately handling
derived types, because it will provide additional context about how
the derived type is to be used.

Change-Id: I9d7dcf9d32dada032ff411cd103b9df413c298a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/410101
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2022-06-03 14:30:04 -07:00
parent 1a6c96bb9b
commit 8ef8b60e18
3 changed files with 58 additions and 21 deletions

View file

@ -1567,9 +1567,6 @@ func (r *reader) expr() (res ir.Node) {
// TODO(mdempsky): Handle builtins directly in exprCall, like method calls?
return typecheck.Callee(r.obj())
case exprType:
return r.exprType(false)
case exprConst:
pos := r.pos()
typ := r.typ()
@ -1585,18 +1582,23 @@ func (r *reader) expr() (res ir.Node) {
return r.funcLit()
case exprSelector:
x := r.expr()
var x ir.Node
if r.Bool() { // MethodExpr
x = r.exprType(false)
// Method expression with derived receiver type.
if x.Op() == ir.ODYNAMICTYPE {
// TODO(mdempsky): Handle with runtime dictionary lookup.
n := ir.TypeNode(x.Type())
n.SetTypecheck(1)
x = n
}
} else { // FieldVal, MethodVal
x = r.expr()
}
pos := r.pos()
_, sym := r.selector()
// Method expression with derived receiver type.
if x.Op() == ir.ODYNAMICTYPE {
// TODO(mdempsky): Handle with runtime dictionary lookup.
n := ir.TypeNode(x.Type())
n.SetTypecheck(1)
x = n
}
n := typecheck.Expr(ir.NewSelectorExpr(pos, ir.OXDOT, x, sym)).(*ir.SelectorExpr)
if n.Op() == ir.OMETHVALUE {
wrapper := methodValueWrapper{
@ -1679,6 +1681,17 @@ func (r *reader) expr() (res ir.Node) {
dots := r.Bool()
return typecheck.Call(pos, fun, args, dots)
case exprMake:
pos := r.pos()
typ := r.exprType(false)
extra := r.exprs()
return typecheck.Expr(ir.NewCallExpr(pos, ir.OMAKE, nil, append([]ir.Node{typ}, extra...)))
case exprNew:
pos := r.pos()
typ := r.exprType(false)
return typecheck.Expr(ir.NewUnaryExpr(pos, ir.ONEW, typ))
case exprConvert:
typ := r.typ()
pos := r.pos()