@@ -1889,6 +1889,11 @@ SILFunction *ReabstractionThunkGenerator::createThunk() {
1889
1889
1890
1890
Thunk->setGenericEnvironment (ReInfo.getSpecializedGenericEnvironment ());
1891
1891
1892
+ // Set proper generic context scope for the type lowering.
1893
+ CanSILFunctionType SpecType = SpecializedFunc->getLoweredFunctionType ();
1894
+ Lowering::GenericContextScope GenericScope (M.Types ,
1895
+ SpecType->getGenericSignature ());
1896
+
1892
1897
SILBasicBlock *EntryBB = Thunk->createBasicBlock ();
1893
1898
SILBuilder Builder (EntryBB);
1894
1899
@@ -1953,12 +1958,14 @@ SILValue ReabstractionThunkGenerator::createReabstractionThunkApply(
1953
1958
SILBasicBlock *ErrorBB = Thunk->createBasicBlock ();
1954
1959
Builder.createTryApply (Loc, FRI, CalleeSILSubstFnTy, Subs,
1955
1960
Arguments, NormalBB, ErrorBB);
1956
- auto *ErrorVal = ErrorBB->createPHIArgument (specConv.getSILErrorType (),
1957
- ValueOwnershipKind::Owned);
1961
+ auto *ErrorVal = ErrorBB->createPHIArgument (
1962
+ SpecializedFunc->mapTypeIntoContext (specConv.getSILErrorType ()),
1963
+ ValueOwnershipKind::Owned);
1958
1964
Builder.setInsertionPoint (ErrorBB);
1959
1965
Builder.createThrow (Loc, ErrorVal);
1960
1966
SILValue ReturnValue = NormalBB->createPHIArgument (
1961
- specConv.getSILResultType (), ValueOwnershipKind::Owned);
1967
+ SpecializedFunc->mapTypeIntoContext (specConv.getSILResultType ()),
1968
+ ValueOwnershipKind::Owned);
1962
1969
Builder.setInsertionPoint (NormalBB);
1963
1970
return ReturnValue;
1964
1971
}
@@ -1980,9 +1987,6 @@ SILArgument *ReabstractionThunkGenerator::convertReabstractionThunkArguments(
1980
1987
1981
1988
assert (specConv.useLoweredAddresses ());
1982
1989
1983
- Lowering::GenericContextScope GenericScope (M.Types ,
1984
- SpecType->getGenericSignature ());
1985
-
1986
1990
// ReInfo.NumIndirectResults corresponds to SubstTy's formal indirect
1987
1991
// results. SpecTy may have fewer formal indirect results.
1988
1992
assert (SubstType->getNumIndirectFormalResults ()
0 commit comments