File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
src/cmd/compile/internal/gc Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,17 @@ func typecheckclosure(clo *Node, top int) {
108
108
109
109
xfunc .Func .Nname .Sym = closurename (Curfn )
110
110
disableExport (xfunc .Func .Nname .Sym )
111
- declare (xfunc .Func .Nname , PFUNC )
111
+ if xfunc .Func .Nname .Sym .Def != nil {
112
+ // The only case we can reach here is when the outer function was redeclared.
113
+ // In that case, don't bother to redeclare the closure. Otherwise, we will get
114
+ // a spurious error message, see #17758. While we are here, double check that
115
+ // we already reported other error.
116
+ if nsavederrors + nerrors == 0 {
117
+ Fatalf ("unexpected symbol collision %v" , xfunc .Func .Nname .Sym )
118
+ }
119
+ } else {
120
+ declare (xfunc .Func .Nname , PFUNC )
121
+ }
112
122
xfunc = typecheck (xfunc , ctxStmt )
113
123
114
124
// Type check the body now, but only if we're inside a function.
Original file line number Diff line number Diff line change
1
+ // errorcheck
2
+
3
+ // Copyright 2020 The Go Authors. All rights reserved.
4
+ // Use of this source code is governed by a BSD-style
5
+ // license that can be found in the LICENSE file.
6
+
7
+ package main
8
+
9
+ func foo () {
10
+ _ = func () {}
11
+ }
12
+
13
+ func foo () { // ERROR "foo redeclared in this block"
14
+ _ = func () {}
15
+ }
16
+
17
+ func main () {}
You can’t perform that action at this time.
0 commit comments