xfunc.Func.Nname.Sym = closurename(Curfn)
disableExport(xfunc.Func.Nname.Sym)
- declare(xfunc.Func.Nname, PFUNC)
+ 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)
+ }
xfunc = typecheck(xfunc, ctxStmt)
// Type check the body now, but only if we're inside a function.
--- /dev/null
+// errorcheck
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func foo() {
+ _ = func() {}
+}
+
+func foo() { // ERROR "foo redeclared in this block"
+ _ = func() {}
+}
+
+func main() {}