@@ -1768,14 +1768,15 @@ static void emitIndirectErrorParameter(SILGenFunction &SGF,
17681768
17691769 // The calling convention always uses minimal resilience expansion.
17701770 auto errorConvType = SGF.SGM .Types .getLoweredType (
1771- errorTypeInContext, TypeExpansionContext::minimal ());
1771+ origErrorType, errorTypeInContext, TypeExpansionContext::minimal ());
17721772
17731773 // And the abstraction pattern may force an indirect return even if the
17741774 // concrete type wouldn't normally be returned indirectly.
17751775 if (!SILModuleConventions::isThrownIndirectlyInSIL (errorConvType,
17761776 SGF.SGM .M )) {
17771777 if (!SILModuleConventions (SGF.SGM .M ).useLoweredAddresses ()
1778- || origErrorType.getErrorConvention (SGF.SGM .Types ) != AbstractionPattern::Indirect)
1778+ || origErrorType.getErrorConvention (SGF.SGM .Types )
1779+ != AbstractionPattern::Indirect)
17791780 return ;
17801781 }
17811782
@@ -1813,10 +1814,16 @@ uint16_t SILGenFunction::emitBasicProlog(
18131814
18141815 llvm::Optional<AbstractionPattern> origErrorType;
18151816 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+
18201827 emitIndirectErrorParameter (*this , *errorType, *origErrorType, DC);
18211828 }
18221829
0 commit comments