mirror of
https://github.com/golang/go
synced 2024-11-26 10:58:16 -07:00
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 #45743. Change-Id: I8b38e5d8b2329ad242de97670f2141f713954d28 Reviewed-on: https://go-review.googlesource.com/c/go/+/313289 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Dan Scales <danscales@google.com> Trust: Dan Scales <danscales@google.com> Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
a53dc4c1ce
commit
9f601690da
@ -1194,6 +1194,8 @@ func (subst *inlsubst) clovar(n *ir.Name) *ir.Name {
|
||||
case *ir.AssignStmt, *ir.AssignListStmt:
|
||||
// Mark node for reassignment at the end of inlsubst.node.
|
||||
m.Defn = &subst.defnMarker
|
||||
case *ir.TypeSwitchGuard:
|
||||
// TODO(mdempsky): Set m.Defn properly. See discussion on #45743.
|
||||
default:
|
||||
base.FatalfAt(n.Pos(), "unexpected Defn: %+v", defn)
|
||||
}
|
||||
|
20
test/fixedbugs/issue45743.go
Normal file
20
test/fixedbugs/issue45743.go
Normal file
@ -0,0 +1,20 @@
|
||||
// compile
|
||||
|
||||
// Copyright 2021 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 fn() func(interface{}) {
|
||||
return func(o interface{}) {
|
||||
switch v := o.(type) {
|
||||
case *int:
|
||||
*v = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
fn()
|
||||
}
|
Loading…
Reference in New Issue
Block a user