Skip to content

Commit 6014f1d

Browse files
committed
SILGen: just for fun let's do toll-free bridging for <T : NSError> archetypes too
Swift SVN r31262
1 parent e5cb73f commit 6014f1d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/SIL/SILType.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,12 @@ static bool isBridgedErrorClass(SILModule &M,
279279
if (!t)
280280
return false;
281281

282+
if (auto archetypeType = t->getAs<ArchetypeType>())
283+
t = archetypeType->getSuperclass();
284+
282285
// NSError (TODO: and CFError) can be bridged.
283286
auto errorType = M.Types.getNSErrorType();
284-
if (errorType && t->isEqual(errorType)) {
287+
if (t && errorType && t->isEqual(errorType)) {
285288
return true;
286289
}
287290

test/SILGen/objc_error.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ func NSErrorErrorType_erasure(x: NSError) -> ErrorType {
1111
return x
1212
}
1313

14+
// CHECK-LABEL: sil hidden @_TF10objc_error34NSErrorErrorType_archetype_erasureuRdq_CSo7NSError_Fq_PSs9ErrorType_
15+
// CHECK: [[ERROR_TYPE:%.*]] = init_existential_ref %0 : $T : $T, $ErrorType
16+
// CHECK: return [[ERROR_TYPE]]
17+
func NSErrorErrorType_archetype_erasure<T : NSError>(t: T) -> ErrorType {
18+
return t
19+
}
20+
1421
// Test patterns that are non-trivial, but irrefutable. SILGen shouldn't crash
1522
// on these.
1623
func test_doesnt_throw() {

0 commit comments

Comments
 (0)