Skip to content

Commit 2ac4b42

Browse files
committed
SIL: Fix assertion failure when function with opaque result type returns a tuple
1 parent 60c947f commit 2ac4b42

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/SIL/AbstractionPattern.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,16 @@ bool AbstractionPattern::matchesTuple(CanTupleType substType) {
274274
return getNumTupleElements_Stored() == substType->getNumElements();
275275
case Kind::ClangType:
276276
case Kind::Type:
277-
case Kind::Discard:
277+
case Kind::Discard: {
278278
if (isTypeParameter())
279279
return true;
280-
auto tuple = dyn_cast<TupleType>(getType());
281-
return (tuple && tuple->getNumElements() == substType->getNumElements());
280+
auto type = getType();
281+
if (auto tuple = dyn_cast<TupleType>(type))
282+
return (tuple->getNumElements() == substType->getNumElements());
283+
if (isa<OpaqueTypeArchetypeType>(type))
284+
return true;
285+
return false;
286+
}
282287
}
283288
llvm_unreachable("bad kind");
284289
}

test/SILGen/opaque_result_type.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,11 @@ public class D {
165165
return d
166166
}()
167167
}
168+
169+
// CHECK-LABEL: sil [ossa] @$s18opaque_result_type10tupleAsAnyQryF : $@convention(thin) () -> @out @_opaqueReturnTypeOf("$s18opaque_result_type10tupleAsAnyQryF", 0) 🦸 {
170+
public func tupleAsAny() -> some Any {
171+
// CHECK-NEXT: bb0(%0 : $*()):
172+
// CHECK-NEXT: %1 = tuple ()
173+
// CHECK-NEXT: return %1 : $()
174+
return ()
175+
}

0 commit comments

Comments
 (0)