@@ -684,19 +684,25 @@ func (b *builder) createTypeAssert(expr *ssa.TypeAssert) llvm.Value {
684
684
685
685
actualTypeNum := b .CreateExtractValue (itf , 0 , "interface.type" )
686
686
commaOk := llvm.Value {}
687
- if _ , ok := expr .AssertedType .Underlying ().(* types.Interface ); ok {
688
- // Type assert on interface type.
689
- // This is a call to an interface type assert function.
690
- // The interface lowering pass will define this function by filling it
691
- // with a type switch over all concrete types that implement this
692
- // interface, and returning whether it's one of the matched types.
693
- // This is very different from how interface asserts are implemented in
694
- // the main Go compiler, where the runtime checks whether the type
695
- // implements each method of the interface. See:
696
- // https://research.swtch.com/interfaces
697
- fn := b .getInterfaceImplementsFunc (expr .AssertedType )
698
- commaOk = b .CreateCall (fn .GlobalValueType (), fn , []llvm.Value {actualTypeNum }, "" )
699
687
688
+ if intf , ok := expr .AssertedType .Underlying ().(* types.Interface ); ok {
689
+ if intf .Empty () {
690
+ // intf is the empty interface => no methods
691
+ // This type assertion always succeeds, so we can just set commaOk to true.
692
+ commaOk = llvm .ConstInt (b .ctx .Int1Type (), 1 , true )
693
+ } else {
694
+ // Type assert on interface type with methods.
695
+ // This is a call to an interface type assert function.
696
+ // The interface lowering pass will define this function by filling it
697
+ // with a type switch over all concrete types that implement this
698
+ // interface, and returning whether it's one of the matched types.
699
+ // This is very different from how interface asserts are implemented in
700
+ // the main Go compiler, where the runtime checks whether the type
701
+ // implements each method of the interface. See:
702
+ // https://research.swtch.com/interfaces
703
+ fn := b .getInterfaceImplementsFunc (expr .AssertedType )
704
+ commaOk = b .CreateCall (fn .GlobalValueType (), fn , []llvm.Value {actualTypeNum }, "" )
705
+ }
700
706
} else {
701
707
name , _ := getTypeCodeName (expr .AssertedType )
702
708
globalName := "reflect/types.typeid:" + name
0 commit comments