}
n := newname(sym)
- n.SetClass(PFUNC)
- n.Sym.SetFunc(true)
+ setNodeNameFunc(n)
n.Type = functype(nil, []*Node{
anonfield(types.NewPtr(t)),
anonfield(types.Types[TUINTPTR]),
}
xfunc.Func.Nname.Sym = closurename(Curfn)
- disableExport(xfunc.Func.Nname.Sym)
- if xfunc.Func.Nname.Sym.Def != nil {
- // The only case we can reach here is when the outer function was redeclared.
- // In that case, don't bother to redeclare the closure. Otherwise, we will get
- // a spurious error message, see #17758. While we are here, double check that
- // we already reported other error.
- if nsavederrors+nerrors == 0 {
- Fatalf("unexpected symbol collision %v", xfunc.Func.Nname.Sym)
- }
- } else {
- declare(xfunc.Func.Nname, PFUNC)
- }
+ setNodeNameFunc(xfunc.Func.Nname)
xfunc = typecheck(xfunc, ctxStmt)
// Type check the body now, but only if we're inside a function.
tfn.List.Set(structargs(t0.Params(), true))
tfn.Rlist.Set(structargs(t0.Results(), false))
- disableExport(sym)
xfunc := dclfunc(sym, tfn)
xfunc.Func.SetDupok(true)
xfunc.Func.SetNeedctxt(true)
}
}
-// disableExport prevents sym from being included in package export
-// data. To be effectual, it must be called before declare.
-func disableExport(sym *types.Sym) {
- sym.SetOnExportList(true)
+// setNodeNameFunc marks a node as a function.
+func setNodeNameFunc(n *Node) {
+ if n.Op != ONAME || n.Class() != Pxxx {
+ Fatalf("expected ONAME/Pxxx node, got %v", n)
+ }
+
+ n.SetClass(PFUNC)
+ n.Sym.SetFunc(true)
}
func dclfunc(sym *types.Sym, tfn *Node) *Node {
fn.Func.Nname = newfuncnamel(lineno, sym)
fn.Func.Nname.Name.Defn = fn
fn.Func.Nname.Name.Param.Ntype = tfn
- declare(fn.Func.Nname, PFUNC)
+ setNodeNameFunc(fn.Func.Nname)
funchdr(fn)
fn.Func.Nname.Name.Param.Ntype = typecheck(fn.Func.Nname.Name.Param.Ntype, ctxType)
return fn
if len(nf) > 0 {
lineno = nf[0].Pos // prolog/epilog gets line number of first init stmt
initializers := lookup("init")
- disableExport(initializers)
fn := dclfunc(initializers, nod(OTFUNC, nil, nil))
for _, dcl := range dummyInitFn.Func.Dcl {
dcl.Name.Curfn = fn
tfn.List.Set(structargs(method.Type.Params(), true))
tfn.Rlist.Set(structargs(method.Type.Results(), false))
- disableExport(newnam)
fn := dclfunc(newnam, tfn)
fn.Func.SetDupok(true)
sym := Runtimepkg.Lookup("memhash")
n := newname(sym)
- n.SetClass(PFUNC)
- n.Sym.SetFunc(true)
+ setNodeNameFunc(n)
n.Type = functype(nil, []*Node{
anonfield(types.NewPtr(t)),
anonfield(types.Types[TUINTPTR]),
case ASPECIAL:
sym := typesymprefix(".eq", t)
n := newname(sym)
- n.SetClass(PFUNC)
- n.Sym.SetFunc(true)
+ setNodeNameFunc(n)
n.Type = functype(nil, []*Node{
anonfield(types.NewPtr(t)),
anonfield(types.NewPtr(t)),