mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] cmd/compile: small fixes for stenciling
- Create the stencil name using targ.Type.String(), which handles cases where, for example, a type argument is a pointer to a named type, etc. *obj. - Set name.Def properly for a new stenciled func (have the symbol point back to the associated function node). Will be required when exporting. - Add missing copying of Func field when making copies of Name nodes. (On purpose (it seems), Name nodes don't have a copy() function, so we have to copy all the needed fields explicitly.) - Deal with nil type in subster.node(), which is the type of the return value for a function that doesn't return anything. - Fix min to match standard want/go form, and add in float tests. Changed Got -> got in bunch of other typeparam tests. - Add new tests index.go, settable.go, and smallest.go (similar to examples in the type param proposal), some of which need the above changes. Change-Id: I09a72302bc1fd3635a326da92405222afa222e85 Reviewed-on: https://go-review.googlesource.com/c/go/+/291109 Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
df23540dde
commit
c0aa7bd760
8 changed files with 166 additions and 19 deletions
|
|
@ -80,7 +80,7 @@ func makeInstName(inst *ir.InstExpr) *types.Sym {
|
|||
if i > 0 {
|
||||
b.WriteString(",")
|
||||
}
|
||||
b.WriteString(targ.Name().Sym().Name)
|
||||
b.WriteString(targ.Type().String())
|
||||
}
|
||||
b.WriteString("]")
|
||||
return typecheck.Lookup(b.String())
|
||||
|
|
@ -107,6 +107,7 @@ func genericSubst(name *types.Sym, inst *ir.InstExpr) *ir.Func {
|
|||
newf.Nname = ir.NewNameAt(inst.Pos(), name)
|
||||
newf.Nname.Func = newf
|
||||
newf.Nname.Defn = newf
|
||||
name.Def = newf.Nname
|
||||
|
||||
subst := &subster{
|
||||
newf: newf,
|
||||
|
|
@ -160,6 +161,7 @@ func (subst *subster) node(n ir.Node) ir.Node {
|
|||
m.SetType(newt)
|
||||
m.Curfn = subst.newf
|
||||
m.Class = name.Class
|
||||
m.Func = name.Func
|
||||
subst.vars[name] = m
|
||||
m.SetTypecheck(1)
|
||||
return m
|
||||
|
|
@ -170,7 +172,17 @@ func (subst *subster) node(n ir.Node) ir.Node {
|
|||
}
|
||||
m := ir.Copy(x)
|
||||
if _, isExpr := m.(ir.Expr); isExpr {
|
||||
m.SetType(subst.typ(x.Type()))
|
||||
t := x.Type()
|
||||
if t == nil {
|
||||
// t can be nil only if this is a call that has no
|
||||
// return values, so allow that and otherwise give
|
||||
// an error.
|
||||
if _, isCallExpr := m.(*ir.CallExpr); !isCallExpr {
|
||||
base.Fatalf(fmt.Sprintf("Nil type for %v", x))
|
||||
}
|
||||
} else {
|
||||
m.SetType(subst.typ(x.Type()))
|
||||
}
|
||||
}
|
||||
ir.EditChildren(m, edit)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue