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