@@ -412,8 +412,8 @@ bool TypeChecker::isRepresentableInObjC(
412
412
errorConvention = None;
413
413
414
414
// If you change this function, you must add or modify a test in PrintAsObjC.
415
-
416
- bool Diagnose = shouldDiagnoseObjCReason (Reason, Context );
415
+ ASTContext &ctx = AFD-> getASTContext ();
416
+ bool Diagnose = shouldDiagnoseObjCReason (Reason, ctx );
417
417
418
418
if (checkObjCInForeignClassContext (AFD, Reason))
419
419
return false ;
@@ -423,17 +423,16 @@ bool TypeChecker::isRepresentableInObjC(
423
423
return false ;
424
424
425
425
if (AFD->isOperator ()) {
426
- diagnose (AFD, (isa<ProtocolDecl>(AFD->getDeclContext ())
427
- ? diag::objc_operator_proto
428
- : diag::objc_operator));
426
+ AFD-> diagnose ((isa<ProtocolDecl>(AFD->getDeclContext ())
427
+ ? diag::objc_operator_proto
428
+ : diag::objc_operator));
429
429
return false ;
430
430
}
431
431
432
432
if (auto accessor = dyn_cast<AccessorDecl>(AFD)) {
433
433
// Accessors can only be @objc if the storage declaration is.
434
434
// Global computed properties may however @_cdecl their accessors.
435
435
auto storage = accessor->getStorage ();
436
- validateDecl (storage);
437
436
if (!storage->isObjC () && Reason != ObjCReason::ExplicitlyCDecl &&
438
437
Reason != ObjCReason::WitnessToObjC) {
439
438
if (Diagnose) {
@@ -445,7 +444,7 @@ bool TypeChecker::isRepresentableInObjC(
445
444
? diag::objc_setter_for_nonobjc_property
446
445
: diag::objc_setter_for_nonobjc_subscript);
447
446
448
- diagnose ( accessor->getLoc (), error);
447
+ accessor->diagnose ( error);
449
448
describeObjCReason (accessor, Reason);
450
449
}
451
450
return false ;
@@ -457,7 +456,7 @@ bool TypeChecker::isRepresentableInObjC(
457
456
// willSet/didSet implementations are never exposed to objc, they are
458
457
// always directly dispatched from the synthesized setter.
459
458
if (Diagnose) {
460
- diagnose ( accessor->getLoc (), diag::objc_observing_accessor);
459
+ accessor->diagnose ( diag::objc_observing_accessor);
461
460
describeObjCReason (accessor, Reason);
462
461
}
463
462
return false ;
@@ -473,7 +472,7 @@ bool TypeChecker::isRepresentableInObjC(
473
472
case AccessorKind::Address:
474
473
case AccessorKind::MutableAddress:
475
474
if (Diagnose) {
476
- diagnose ( accessor->getLoc (), diag::objc_addressor);
475
+ accessor->diagnose ( diag::objc_addressor);
477
476
describeObjCReason (accessor, Reason);
478
477
}
479
478
return false ;
@@ -513,8 +512,8 @@ bool TypeChecker::isRepresentableInObjC(
513
512
!ResultType->isRepresentableIn (ForeignLanguage::ObjectiveC,
514
513
const_cast <FuncDecl *>(FD))) {
515
514
if (Diagnose) {
516
- diagnose ( AFD->getLoc (), diag::objc_invalid_on_func_result_type,
517
- getObjCDiagnosticAttrKind (Reason));
515
+ AFD->diagnose ( diag::objc_invalid_on_func_result_type,
516
+ getObjCDiagnosticAttrKind (Reason));
518
517
SourceRange Range =
519
518
FD->getBodyResultTypeLoc ().getTypeRepr ()->getSourceRange ();
520
519
diagnoseTypeNotRepresentableInObjC (FD, ResultType, Range);
@@ -549,8 +548,8 @@ bool TypeChecker::isRepresentableInObjC(
549
548
// Only non-failing initializers can throw.
550
549
if (ctor->getFailability () != OTK_None) {
551
550
if (Diagnose) {
552
- diagnose ( AFD->getLoc (), diag::objc_invalid_on_failing_init,
553
- getObjCDiagnosticAttrKind (Reason))
551
+ AFD->diagnose ( diag::objc_invalid_on_failing_init,
552
+ getObjCDiagnosticAttrKind (Reason))
554
553
.highlight (throwsLoc);
555
554
describeObjCReason (AFD, Reason);
556
555
}
@@ -561,15 +560,15 @@ bool TypeChecker::isRepresentableInObjC(
561
560
// Functions that return nothing (void) can be throwing; they indicate
562
561
// failure with a 'false' result.
563
562
kind = ForeignErrorConvention::ZeroResult;
564
- NominalTypeDecl *boolDecl = Context .getObjCBoolDecl ();
563
+ NominalTypeDecl *boolDecl = ctx .getObjCBoolDecl ();
565
564
// On Linux, we might still run @objc tests even though there's
566
565
// no ObjectiveC Foundation, so use Swift.Bool instead of crapping
567
566
// out.
568
567
if (boolDecl == nullptr )
569
- boolDecl = Context .getBoolDecl ();
568
+ boolDecl = ctx .getBoolDecl ();
570
569
571
570
if (boolDecl == nullptr ) {
572
- diagnose ( AFD->getLoc (), diag::broken_bool);
571
+ AFD->diagnose ( diag::broken_bool);
573
572
return false ;
574
573
}
575
574
@@ -584,21 +583,19 @@ bool TypeChecker::isRepresentableInObjC(
584
583
// Cannot return an optional bridged type, because 'nil' is reserved
585
584
// to indicate failure. Call this out in a separate diagnostic.
586
585
if (Diagnose) {
587
- diagnose (AFD->getLoc (),
588
- diag::objc_invalid_on_throwing_optional_result,
589
- getObjCDiagnosticAttrKind (Reason),
590
- resultType)
586
+ AFD->diagnose (diag::objc_invalid_on_throwing_optional_result,
587
+ getObjCDiagnosticAttrKind (Reason),
588
+ resultType)
591
589
.highlight (throwsLoc);
592
590
describeObjCReason (AFD, Reason);
593
591
}
594
592
return false ;
595
593
} else {
596
594
// Other result types are not permitted.
597
595
if (Diagnose) {
598
- diagnose (AFD->getLoc (),
599
- diag::objc_invalid_on_throwing_result,
600
- getObjCDiagnosticAttrKind (Reason),
601
- resultType)
596
+ AFD->diagnose (diag::objc_invalid_on_throwing_result,
597
+ getObjCDiagnosticAttrKind (Reason),
598
+ resultType)
602
599
.highlight (throwsLoc);
603
600
describeObjCReason (AFD, Reason);
604
601
}
@@ -611,7 +608,7 @@ bool TypeChecker::isRepresentableInObjC(
611
608
errorParameterType = OptionalType::get (errorParameterType);
612
609
errorParameterType
613
610
= BoundGenericType::get (
614
- Context .getAutoreleasingUnsafeMutablePointerDecl (),
611
+ ctx .getAutoreleasingUnsafeMutablePointerDecl (),
615
612
nullptr ,
616
613
errorParameterType);
617
614
errorParameterType = OptionalType::get (errorParameterType);
@@ -630,7 +627,7 @@ bool TypeChecker::isRepresentableInObjC(
630
627
// If the selector piece is "error", this is the location of
631
628
// the error parameter.
632
629
auto piece = selectorPieces[i-1 ];
633
- if (piece == Context .Id_error ) {
630
+ if (piece == ctx .Id_error ) {
634
631
errorParameterIndex = i-1 ;
635
632
foundErrorParameterIndex = true ;
636
633
break ;
@@ -732,7 +729,7 @@ bool TypeChecker::isRepresentableInObjC(
732
729
return true ;
733
730
}
734
731
735
- bool TypeChecker ::isRepresentableInObjC (const VarDecl *VD, ObjCReason Reason) {
732
+ bool swift ::isRepresentableInObjC (const VarDecl *VD, ObjCReason Reason) {
736
733
// If you change this function, you must add or modify a test in PrintAsObjC.
737
734
738
735
if (VD->isInvalid ())
@@ -746,9 +743,10 @@ bool TypeChecker::isRepresentableInObjC(const VarDecl *VD, ObjCReason Reason) {
746
743
// Because of this, look through @weak and @unowned.
747
744
T = RST->getReferentType ();
748
745
}
746
+ ASTContext &ctx = VD->getASTContext ();
749
747
bool Result = T->isRepresentableIn (ForeignLanguage::ObjectiveC,
750
748
VD->getDeclContext ());
751
- bool Diagnose = shouldDiagnoseObjCReason (Reason, Context );
749
+ bool Diagnose = shouldDiagnoseObjCReason (Reason, ctx );
752
750
753
751
if (Result && checkObjCInExtensionContext (VD, Diagnose))
754
752
return false ;
@@ -764,8 +762,7 @@ bool TypeChecker::isRepresentableInObjC(const VarDecl *VD, ObjCReason Reason) {
764
762
if (TypeRange.isInvalid ())
765
763
TypeRange = VD->getNameLoc ();
766
764
767
- diagnose (VD->getLoc (), diag::objc_invalid_on_var,
768
- getObjCDiagnosticAttrKind (Reason))
765
+ VD->diagnose (diag::objc_invalid_on_var, getObjCDiagnosticAttrKind (Reason))
769
766
.highlight (TypeRange);
770
767
diagnoseTypeNotRepresentableInObjC (VD->getDeclContext (),
771
768
VD->getInterfaceType (),
@@ -775,11 +772,10 @@ bool TypeChecker::isRepresentableInObjC(const VarDecl *VD, ObjCReason Reason) {
775
772
return Result;
776
773
}
777
774
778
- bool TypeChecker::isRepresentableInObjC (const SubscriptDecl *SD,
779
- ObjCReason Reason) {
775
+ bool swift::isRepresentableInObjC (const SubscriptDecl *SD, ObjCReason Reason) {
780
776
// If you change this function, you must add or modify a test in PrintAsObjC.
781
-
782
- bool Diagnose = shouldDiagnoseObjCReason (Reason, Context );
777
+ ASTContext &ctx = SD-> getASTContext ();
778
+ bool Diagnose = shouldDiagnoseObjCReason (Reason, ctx );
783
779
784
780
if (checkObjCInForeignClassContext (SD, Reason))
785
781
return false ;
@@ -805,8 +801,8 @@ bool TypeChecker::isRepresentableInObjC(const SubscriptDecl *SD,
805
801
// Make sure we know how to map the selector appropriately.
806
802
if (Result && SD->getObjCSubscriptKind () == ObjCSubscriptKind::None) {
807
803
SourceRange IndexRange = SD->getIndices ()->getSourceRange ();
808
- diagnose ( SD->getLoc (), diag::objc_invalid_subscript_key_type,
809
- getObjCDiagnosticAttrKind (Reason), IndicesType)
804
+ SD->diagnose ( diag::objc_invalid_subscript_key_type,
805
+ getObjCDiagnosticAttrKind (Reason), IndicesType)
810
806
.highlight (IndexRange);
811
807
return false ;
812
808
}
@@ -819,8 +815,8 @@ bool TypeChecker::isRepresentableInObjC(const SubscriptDecl *SD,
819
815
TypeRange = SD->getIndices ()->getSourceRange ();
820
816
else
821
817
TypeRange = SD->getElementTypeLoc ().getSourceRange ();
822
- diagnose ( SD->getLoc (), diag::objc_invalid_on_subscript,
823
- getObjCDiagnosticAttrKind (Reason))
818
+ SD->diagnose ( diag::objc_invalid_on_subscript,
819
+ getObjCDiagnosticAttrKind (Reason))
824
820
.highlight (TypeRange);
825
821
826
822
diagnoseTypeNotRepresentableInObjC (SD->getDeclContext (),
@@ -843,11 +839,12 @@ bool TypeChecker::canBeRepresentedInObjC(const ValueDecl *decl) {
843
839
}
844
840
845
841
if (auto var = dyn_cast<VarDecl>(decl))
846
- return isRepresentableInObjC (var, ObjCReason::MemberOfObjCMembersClass);
842
+ return swift::isRepresentableInObjC (var,
843
+ ObjCReason::MemberOfObjCMembersClass);
847
844
848
845
if (auto subscript = dyn_cast<SubscriptDecl>(decl))
849
- return isRepresentableInObjC (subscript,
850
- ObjCReason::MemberOfObjCMembersClass);
846
+ return swift:: isRepresentableInObjC (subscript,
847
+ ObjCReason::MemberOfObjCMembersClass);
851
848
852
849
return false ;
853
850
}
0 commit comments