Skip to content

Commit 9f60169

Browse files
committed
cmd/compile: workaround inlining of closures with type switches
Within clovar, n.Defn can also be *ir.TypeSwitchGuard. The proper fix here would be to populate m.Defn and have it filled in too, but we already leave it nil in inlvar. So for consistency, this CL does the same in clovar too. Eventually inl.go should be rewritten to fully respect IR invariants. Fixes golang#45743. Change-Id: I8b38e5d8b2329ad242de97670f2141f713954d28 Reviewed-on: https://go-review.googlesource.com/c/go/+/313289 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Dan Scales <[email protected]> Trust: Dan Scales <[email protected]> Trust: Cuong Manh Le <[email protected]>
1 parent a53dc4c commit 9f60169

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/cmd/compile/internal/inline/inl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,8 @@ func (subst *inlsubst) clovar(n *ir.Name) *ir.Name {
11941194
case *ir.AssignStmt, *ir.AssignListStmt:
11951195
// Mark node for reassignment at the end of inlsubst.node.
11961196
m.Defn = &subst.defnMarker
1197+
case *ir.TypeSwitchGuard:
1198+
// TODO(mdempsky): Set m.Defn properly. See discussion on #45743.
11971199
default:
11981200
base.FatalfAt(n.Pos(), "unexpected Defn: %+v", defn)
11991201
}

test/fixedbugs/issue45743.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// compile
2+
3+
// Copyright 2021 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 fn() func(interface{}) {
10+
return func(o interface{}) {
11+
switch v := o.(type) {
12+
case *int:
13+
*v = 1
14+
}
15+
}
16+
}
17+
18+
func main() {
19+
fn()
20+
}

0 commit comments

Comments
 (0)