Skip to content

Commit 54754c5

Browse files
committed
SILGen: Fix dynamic calls of 'throwing' methods
Fixes <https://bugs.swift.org/browse/SR-2320>.
1 parent ab81426 commit 54754c5

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,14 @@ class Callee {
558558
assert(level <= Constant.uncurryLevel
559559
&& "uncurrying past natural uncurry level of method");
560560

561-
auto constant = Constant.atUncurryLevel(level);
561+
constant = Constant.atUncurryLevel(level);
562562
// Lower the substituted type from the AST, which should have any generic
563563
// parameters in the original signature erased to their upper bounds.
564564
auto objcFormalType = SubstFormalType.withExtInfo(
565565
SubstFormalType->getExtInfo()
566566
.withSILRepresentation(SILFunctionTypeRepresentation::ObjCMethod));
567567
auto fnType = gen.SGM.M.Types
568-
.getUncachedSILFunctionTypeForConstant(constant, objcFormalType);
568+
.getUncachedSILFunctionTypeForConstant(*constant, objcFormalType);
569569

570570
auto closureType =
571571
replaceSelfTypeForDynamicLookup(gen.getASTContext(), fnType,
@@ -574,9 +574,9 @@ class Callee {
574574

575575
SILValue fn = gen.B.createDynamicMethod(Loc,
576576
SelfValue,
577-
constant,
577+
*constant,
578578
SILType::getPrimitiveObjectType(closureType),
579-
/*volatile*/ constant.isForeign);
579+
/*volatile*/ Constant.isForeign);
580580
mv = ManagedValue::forUnmanaged(fn);
581581
break;
582582
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: %build-clang-importer-objc-overlays
3+
4+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource -I %t) -emit-silgen -parse-as-library %s | %FileCheck %s
5+
6+
// REQUIRES: objc_interop
7+
8+
import Foundation
9+
10+
class Blub : NSObject {
11+
func blub() throws {}
12+
}
13+
14+
// CHECK-LABEL: sil hidden @_TF21dynamic_lookup_throws8testBlubFzT1aPs9AnyObject__T_ : $@convention(thin) (@owned AnyObject) -> @error Error
15+
func testBlub(a: AnyObject) throws {
16+
// CHECK: open_existential_ref %0 : $AnyObject to $@opened("[[OPENED:.*]]") AnyObject
17+
// CHECK: dynamic_method [volatile] %4 : $@opened("[[OPENED]]") AnyObject, #Blub.blub!1.foreign : (Blub) -> () throws -> (), $@convention(objc_method) (Optional<AutoreleasingUnsafeMutablePointer<Optional<NSError>>>, @opened("[[OPENED]]") AnyObject) -> ObjCBool
18+
// CHECK: cond_br {{%.*}}, bb1, bb2
19+
20+
// CHECK: bb1
21+
// CHECK: return
22+
23+
// CHECK: bb2
24+
// CHECK: function_ref @swift_convertNSErrorToError
25+
// CHECK: throw {{%.*}} : $Error
26+
try a.blub()
27+
}

0 commit comments

Comments
 (0)