@@ -1768,14 +1768,15 @@ static void emitIndirectErrorParameter(SILGenFunction &SGF,
1768
1768
1769
1769
// The calling convention always uses minimal resilience expansion.
1770
1770
auto errorConvType = SGF.SGM .Types .getLoweredType (
1771
- errorTypeInContext, TypeExpansionContext::minimal ());
1771
+ origErrorType, errorTypeInContext, TypeExpansionContext::minimal ());
1772
1772
1773
1773
// And the abstraction pattern may force an indirect return even if the
1774
1774
// concrete type wouldn't normally be returned indirectly.
1775
1775
if (!SILModuleConventions::isThrownIndirectlyInSIL (errorConvType,
1776
1776
SGF.SGM .M )) {
1777
1777
if (!SILModuleConventions (SGF.SGM .M ).useLoweredAddresses ()
1778
- || origErrorType.getErrorConvention (SGF.SGM .Types ) != AbstractionPattern::Indirect)
1778
+ || origErrorType.getErrorConvention (SGF.SGM .Types )
1779
+ != AbstractionPattern::Indirect)
1779
1780
return ;
1780
1781
}
1781
1782
@@ -1813,10 +1814,16 @@ uint16_t SILGenFunction::emitBasicProlog(
1813
1814
1814
1815
llvm::Optional<AbstractionPattern> origErrorType;
1815
1816
if (errorType) {
1816
- origErrorType = origClosureType
1817
- ? origClosureType->getFunctionThrownErrorType ()
1818
- : AbstractionPattern (genericSig.getCanonicalSignature (),
1819
- (*errorType)->getCanonicalType ());
1817
+ if (origClosureType &&
1818
+ !origClosureType->isTypeParameterOrOpaqueArchetype ()) {
1819
+ origErrorType =
1820
+ origClosureType->getFunctionThrownErrorType ();
1821
+ } else {
1822
+ origErrorType =
1823
+ AbstractionPattern (genericSig.getCanonicalSignature (),
1824
+ (*errorType)->getCanonicalType ());
1825
+ }
1826
+
1820
1827
emitIndirectErrorParameter (*this , *errorType, *origErrorType, DC);
1821
1828
}
1822
1829
0 commit comments