@@ -336,10 +336,17 @@ static ManagedValue emitManagedParameter(SILGenFunction &SGF, SILLocation loc,
336
336
337
337
// / Get the type of each parameter, filtering out empty tuples.
338
338
static SmallVector<CanType, 8 >
339
- getParameterTypes (AnyFunctionType::CanParamArrayRef params) {
339
+ getParameterTypes (AnyFunctionType::CanParamArrayRef params,
340
+ bool hasSelfParam=false ) {
340
341
SmallVector<CanType, 8 > results;
341
- for (auto param : params) {
342
- assert (!param.isInOut () && !param.isVariadic ());
342
+ for (auto n : indices (params)) {
343
+ bool isSelf = (hasSelfParam ? n == params.size () - 1 : false );
344
+
345
+ const auto ¶m = params[n];
346
+ assert (isSelf || !param.isInOut () &&
347
+ " Only the 'self' parameter can be inout in a bridging thunk" );
348
+ assert (!param.isVariadic ());
349
+
343
350
if (param.getPlainType ()->isVoid ())
344
351
continue ;
345
352
results.push_back (param.getPlainType ());
@@ -1723,10 +1730,11 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
1723
1730
};
1724
1731
1725
1732
{
1733
+ bool hasSelfParam = fd->hasImplicitSelfDecl ();
1726
1734
auto foreignFormalParams =
1727
- getParameterTypes (foreignCI.LoweredType .getParams ());
1735
+ getParameterTypes (foreignCI.LoweredType .getParams (), hasSelfParam );
1728
1736
auto nativeFormalParams =
1729
- getParameterTypes (nativeCI.LoweredType .getParams ());
1737
+ getParameterTypes (nativeCI.LoweredType .getParams (), hasSelfParam );
1730
1738
1731
1739
for (unsigned nativeParamIndex : indices (params)) {
1732
1740
// Bring the parameter to +1.
@@ -1762,7 +1770,7 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
1762
1770
1763
1771
maybeAddForeignErrorArg ();
1764
1772
1765
- bool isSelf = nativeParamIndex == params.size () - 1 ;
1773
+ bool isSelf = (hasSelfParam && nativeParamIndex == params.size () - 1 ) ;
1766
1774
1767
1775
if (memberStatus.isInstance ()) {
1768
1776
// Leave space for `self` to be filled in later.
@@ -1787,6 +1795,12 @@ void SILGenFunction::emitForeignToNativeThunk(SILDeclRef thunk) {
1787
1795
F.mapTypeIntoContext (foreignFormalParams[nativeParamIndex])
1788
1796
->getCanonicalType ();
1789
1797
1798
+ if (isSelf) {
1799
+ assert (!nativeCI.LoweredType .getParams ()[nativeParamIndex].isInOut () ||
1800
+ nativeFormalType == foreignFormalType &&
1801
+ " Cannot bridge 'self' parameter if passed inout" );
1802
+ }
1803
+
1790
1804
auto foreignParam = foreignFnTy->getParameters ()[foreignArgIndex++];
1791
1805
SILType foreignLoweredTy =
1792
1806
F.mapTypeIntoContext (foreignParam.getSILStorageType (
0 commit comments