@@ -296,21 +296,21 @@ static void diagnoseTypeNotRepresentableInObjC(const DeclContext *DC,
296
296
297
297
static void diagnoseFunctionParamNotRepresentable (
298
298
const AbstractFunctionDecl *AFD, unsigned NumParams,
299
- unsigned ParamIndex, const ParamDecl *P, ObjCReason Reason,
300
- ForeignLanguage Language) {
299
+ unsigned ParamIndex, const ParamDecl *P, ObjCReason Reason) {
301
300
auto behavior = behaviorLimitForObjCReason (Reason, AFD->getASTContext ());
301
+ auto language = Reason.getForeignLanguage ();
302
302
303
303
if (NumParams == 1 ) {
304
304
softenIfAccessNote (AFD, Reason.getAttr (),
305
305
AFD->diagnose (diag::objc_invalid_on_func_single_param_type,
306
306
AFD, getObjCDiagnosticAttrKind (Reason),
307
- (unsigned )Language )
307
+ (unsigned )language )
308
308
.limitBehavior (behavior));
309
309
} else {
310
310
softenIfAccessNote (AFD, Reason.getAttr (),
311
311
AFD->diagnose (diag::objc_invalid_on_func_param_type,
312
312
AFD, ParamIndex + 1 , getObjCDiagnosticAttrKind (Reason),
313
- (unsigned )Language )
313
+ (unsigned )language )
314
314
.limitBehavior (behavior));
315
315
}
316
316
SourceRange SR;
@@ -329,12 +329,12 @@ static void diagnoseFunctionParamNotRepresentable(
329
329
330
330
static bool isParamListRepresentableInLanguage (const AbstractFunctionDecl *AFD,
331
331
const ParameterList *PL,
332
- ObjCReason Reason,
333
- ForeignLanguage Language) {
332
+ ObjCReason Reason) {
334
333
// If you change this function, you must add or modify a test in PrintAsClang.
335
334
ASTContext &ctx = AFD->getASTContext ();
336
335
auto &diags = ctx.Diags ;
337
336
auto behavior = behaviorLimitForObjCReason (Reason, ctx);
337
+ auto language = Reason.getForeignLanguage ();
338
338
bool IsObjC = true ;
339
339
unsigned NumParams = PL->size ();
340
340
for (unsigned ParamIndex = 0 ; ParamIndex != NumParams; ++ParamIndex) {
@@ -356,7 +356,8 @@ static bool isParamListRepresentableInLanguage(const AbstractFunctionDecl *AFD,
356
356
if (param->isInOut ()) {
357
357
softenIfAccessNote (AFD, Reason.getAttr (),
358
358
diags.diagnose (param->getStartLoc (), diag::objc_invalid_on_func_inout,
359
- AFD, getObjCDiagnosticAttrKind (Reason), (unsigned )Language)
359
+ AFD, getObjCDiagnosticAttrKind (Reason),
360
+ (unsigned )language)
360
361
.highlight (param->getSourceRange ())
361
362
.limitBehavior (behavior));
362
363
Reason.describe (AFD);
@@ -369,11 +370,11 @@ static bool isParamListRepresentableInLanguage(const AbstractFunctionDecl *AFD,
369
370
370
371
if (param->hasAttachedPropertyWrapper ()) {
371
372
if (param->getPropertyWrapperBackingPropertyType ()->isRepresentableIn (
372
- Language ,
373
+ language ,
373
374
const_cast <AbstractFunctionDecl *>(AFD)))
374
375
continue ;
375
376
} else if (param->getTypeInContext ()->isRepresentableIn (
376
- Language ,
377
+ language ,
377
378
const_cast <AbstractFunctionDecl *>(AFD))) {
378
379
continue ;
379
380
}
@@ -394,7 +395,7 @@ static bool isParamListRepresentableInLanguage(const AbstractFunctionDecl *AFD,
394
395
395
396
IsObjC = false ;
396
397
diagnoseFunctionParamNotRepresentable (AFD, NumParams, ParamIndex,
397
- param, Reason, Language );
398
+ param, Reason);
398
399
}
399
400
return IsObjC;
400
401
}
@@ -655,13 +656,11 @@ static bool isValidObjectiveCErrorResultType(DeclContext *dc, Type type) {
655
656
bool swift::isRepresentableInLanguage (
656
657
const AbstractFunctionDecl *AFD, ObjCReason Reason,
657
658
std::optional<ForeignAsyncConvention> &asyncConvention,
658
- std::optional<ForeignErrorConvention> &errorConvention,
659
- ForeignLanguage Language) {
659
+ std::optional<ForeignErrorConvention> &errorConvention) {
660
660
auto abiRole = ABIRoleInfo (AFD);
661
661
if (!abiRole.providesAPI () && abiRole.getCounterpart ())
662
662
return isRepresentableInLanguage (abiRole.getCounterpart (), Reason,
663
- asyncConvention, errorConvention,
664
- Language);
663
+ asyncConvention, errorConvention);
665
664
666
665
// Clear out the async and error conventions. They will be added later if
667
666
// needed.
@@ -671,7 +670,7 @@ bool swift::isRepresentableInLanguage(
671
670
// If you change this function, you must add or modify a test in PrintAsClang.
672
671
ASTContext &ctx = AFD->getASTContext ();
673
672
DiagnosticStateRAII diagState (ctx.Diags );
674
-
673
+ auto language = Reason. getForeignLanguage ();
675
674
676
675
if (checkObjCInForeignClassContext (AFD, Reason))
677
676
return false ;
@@ -785,8 +784,7 @@ bool swift::isRepresentableInLanguage(
785
784
if (!isSpecialInit &&
786
785
!isParamListRepresentableInLanguage (AFD,
787
786
AFD->getParameters (),
788
- Reason,
789
- Language)) {
787
+ Reason)) {
790
788
return false ;
791
789
}
792
790
@@ -796,12 +794,12 @@ bool swift::isRepresentableInLanguage(
796
794
!ResultType->hasError () &&
797
795
!ResultType->isVoid () &&
798
796
!ResultType->isUninhabited () &&
799
- !ResultType->isRepresentableIn (Language ,
797
+ !ResultType->isRepresentableIn (language ,
800
798
const_cast <FuncDecl *>(FD))) {
801
799
softenIfAccessNote (AFD, Reason.getAttr (),
802
800
AFD->diagnose (diag::objc_invalid_on_func_result_type,
803
801
FD, getObjCDiagnosticAttrKind (Reason),
804
- (unsigned )Language )
802
+ (unsigned )language )
805
803
.limitBehavior (behavior));
806
804
diagnoseTypeNotRepresentableInObjC (FD, ResultType,
807
805
FD->getResultTypeSourceRange (),
@@ -854,11 +852,11 @@ bool swift::isRepresentableInLanguage(
854
852
completionHandlerParams.push_back (AnyFunctionType::Param (type));
855
853
856
854
// Make sure that the parameter type is representable in Objective-C.
857
- if (!type->isRepresentableIn (Language , const_cast <FuncDecl *>(FD))) {
855
+ if (!type->isRepresentableIn (language , const_cast <FuncDecl *>(FD))) {
858
856
softenIfAccessNote (AFD, Reason.getAttr (),
859
857
AFD->diagnose (diag::objc_invalid_on_func_result_type,
860
858
FD, getObjCDiagnosticAttrKind (Reason),
861
- (unsigned )Language )
859
+ (unsigned )language )
862
860
.limitBehavior (behavior));
863
861
diagnoseTypeNotRepresentableInObjC (FD, type,
864
862
FD->getResultTypeSourceRange (),
@@ -1274,8 +1272,7 @@ bool swift::canBeRepresentedInObjC(const ValueDecl *decl) {
1274
1272
std::optional<ForeignErrorConvention> errorConvention;
1275
1273
return isRepresentableInLanguage (func,
1276
1274
ObjCReason::MemberOfObjCMembersClass,
1277
- asyncConvention, errorConvention,
1278
- ForeignLanguage::ObjectiveC);
1275
+ asyncConvention, errorConvention);
1279
1276
}
1280
1277
1281
1278
if (auto var = dyn_cast<VarDecl>(decl))
@@ -1880,8 +1877,7 @@ bool IsObjCRequest::evaluate(Evaluator &evaluator, ValueDecl *VD) const {
1880
1877
// Destructors need no additional checking.
1881
1878
} else if (auto func = dyn_cast<AbstractFunctionDecl>(VD)) {
1882
1879
if (!isRepresentableInLanguage (
1883
- func, *isObjC, asyncConvention, errorConvention,
1884
- ForeignLanguage::ObjectiveC)) {
1880
+ func, *isObjC, asyncConvention, errorConvention)) {
1885
1881
isObjC->setAttrInvalid ();
1886
1882
return false ;
1887
1883
}
@@ -4174,8 +4170,7 @@ TypeCheckCDeclAttributeRequest::evaluate(Evaluator &evaluator,
4174
4170
4175
4171
std::optional<ForeignAsyncConvention> asyncConvention;
4176
4172
std::optional<ForeignErrorConvention> errorConvention;
4177
- if (isRepresentableInLanguage (FD, reason, asyncConvention, errorConvention,
4178
- *lang)) {
4173
+ if (isRepresentableInLanguage (FD, reason, asyncConvention, errorConvention)) {
4179
4174
if (FD->hasAsync ()) {
4180
4175
FD->setForeignAsyncConvention (*asyncConvention);
4181
4176
ctx.Diags .diagnose (attr->getLocation (), diag::attr_decl_async,
0 commit comments