Skip to content

Commit 0ec4e57

Browse files
committed
also follow OCONVIFACE
1 parent 68ee1cb commit 0ec4e57

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/cmd/compile/internal/ir/expr.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -848,13 +848,7 @@ var Implements = func(t, iface *types.Type) bool {
848848
func StaticType(n Node) *types.Type {
849849
out, typs := staticValue(n, true)
850850

851-
if out.Op() != OCONVIFACE {
852-
return nil
853-
}
854-
855-
recv := out.(*ConvExpr)
856-
857-
typ := recv.X.Type()
851+
typ := out.Type()
858852
if typ.IsInterface() {
859853
return nil
860854
}
@@ -903,6 +897,11 @@ func staticValue(n Node, forDevirt bool) (Node, []*types.Type) {
903897
n = n1.X
904898
continue
905899
}
900+
if forDevirt && n1.Op() == OCONVIFACE {
901+
typeAssertTypes = append(typeAssertTypes, n1.Type())
902+
n = n1.X
903+
continue
904+
}
906905
case *InlinedCallExpr:
907906
if n1.Op() == OINLCALL {
908907
n = n1.SingleResult()

test/escape_iface_with_devirt_type_assertions.go

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ func t() {
4848
a.(M).(A).(*Impl).A() // ERROR "inlining call"
4949
a.(A).(M).(*Impl).M() // ERROR "inlining call"
5050

51+
any(a).(M).M() // ERROR "devirtualizing" "inlining call"
52+
any(a).(A).A() // ERROR "devirtualizing" "inlining call"
53+
any(a).(M).(any).(A).A() // ERROR "devirtualizing" "inlining call"
54+
55+
c := any(a)
56+
c.(A).A() // ERROR "devirtualizing" "inlining call"
57+
c.(M).M() // ERROR "devirtualizing" "inlining call"
58+
5159
{
5260
var a C = &CImpl{} // ERROR "does not escape"
5361
a.(any).(C).C() // ERROR "devirtualizing" "inlining"

0 commit comments

Comments
 (0)