Skip to content

Commit c306fd6

Browse files
committed
cmd/compile: allow loading single field of typed-interface{} OpIData
Same reason as CL 270057, but for OpLoad. Fixes #42727 Change-Id: Iebb1a8110f29427a0aed3b5e3e84f0540de3d1b7 Reviewed-on: https://go-review.googlesource.com/c/go/+/271906 Trust: Cuong Manh Le <[email protected]> Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 5e58ae4 commit c306fd6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/cmd/compile/internal/ssa/expand_calls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func expandCalls(f *Func) {
247247
// i.e., the struct select is generated and remains in because it is not applied to an actual structure.
248248
// The OpLoad was created to load the single field of the IData
249249
// This case removes that StructSelect.
250-
if leafType != selector.Type {
250+
if leafType != selector.Type && !selector.Type.IsEmptyInterface() { // empty interface for #42727
251251
f.Fatalf("Unexpected Load as selector, leaf=%s, selector=%s\n", leaf.LongString(), selector.LongString())
252252
}
253253
leaf.copyOf(selector)

test/fixedbugs/issue42727.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// compile
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+
// Ensure that late expansion correctly handles an OpLoad with type interface{}
8+
9+
package p
10+
11+
type iface interface {
12+
m()
13+
}
14+
15+
type it interface{}
16+
17+
type makeIface func() iface
18+
19+
func f() {
20+
var im makeIface
21+
e := im().(it)
22+
_ = &e
23+
}

0 commit comments

Comments
 (0)