Skip to content

Commit 00d7e41

Browse files
committed
[Typed throws] Always convert error to destination type in calls
An attempted SILGen optimization caused assertions and SIL verification errors. Always convert the error appropriately. Fixes rdar://119214492.
1 parent 49b05ce commit 00d7e41

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/SILGen/SILGenStmt.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1569,7 +1569,7 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
15691569
// If the thrown error type differs from what the throw destination expects,
15701570
// perform the conversion.
15711571
// FIXME: Can the AST tell us what to do here?
1572-
if (exnType != destErrorType && !shouldDiscard) {
1572+
if (exnType != destErrorType) {
15731573
assert(destErrorType == SILType::getExceptionType(getASTContext()));
15741574

15751575
ProtocolConformanceRef conformances[1] = {

test/SILGen/typed_throws.swift

+10
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ func optionalTryDifferent() throws(MyError) {
166166
try? throwsMyBigError()
167167
}
168168

169+
func throwsMyBigErrorOrReturnsInt() throws(MyBigError) -> Int { 5 }
170+
171+
func mightThrowAny(arg: Int) throws { }
172+
173+
// CHECK-LABEL: sil hidden [ossa] @$s12typed_throws14forceTryErasedyyF : $@convention(thin) () -> () {
174+
func forceTryErased() {
175+
// CHECK: try_apply {{.*}} @error MyBigError
176+
// CHECK: try_apply {{.*}} @error any Error
177+
try! mightThrowAny(arg: throwsMyBigErrorOrReturnsInt())
178+
}
169179

170180
// CHECK-LABEL: sil_vtable MySubclass {
171181
// CHECK-NEXT: #MyClass.init!allocator: <E where E : Error> (MyClass.Type) -> (() throws(E) -> ()) throws(E) -> MyClass : @$s12typed_throws10MySubclassC4bodyACyyxYKXE_txYKcs5ErrorRzlufC [override]

0 commit comments

Comments
 (0)