@@ -2684,6 +2684,7 @@ void TypeChecker::checkParameterAttributes(ParameterList *params) {
2684
2684
2685
2685
Type TypeChecker::checkReferenceOwnershipAttr (VarDecl *var, Type type,
2686
2686
ReferenceOwnershipAttr *attr) {
2687
+ auto &Diags = var->getASTContext ().Diags ;
2687
2688
auto *dc = var->getDeclContext ();
2688
2689
2689
2690
// Don't check ownership attribute if the type is invalid.
@@ -2699,18 +2700,16 @@ Type TypeChecker::checkReferenceOwnershipAttr(VarDecl *var, Type type,
2699
2700
switch (optionalityOf (ownershipKind)) {
2700
2701
case ReferenceOwnershipOptionality::Disallowed:
2701
2702
if (isOptional) {
2702
- diagnose (var->getStartLoc (), diag::invalid_ownership_with_optional,
2703
- ownershipKind)
2704
- .fixItReplace (attr->getRange (), " weak" );
2703
+ var->diagnose (diag::invalid_ownership_with_optional, ownershipKind)
2704
+ .fixItReplace (attr->getRange (), " weak" );
2705
2705
attr->setInvalid ();
2706
2706
}
2707
2707
break ;
2708
2708
case ReferenceOwnershipOptionality::Allowed:
2709
2709
break ;
2710
2710
case ReferenceOwnershipOptionality::Required:
2711
2711
if (var->isLet ()) {
2712
- diagnose (var->getStartLoc (), diag::invalid_ownership_is_let,
2713
- ownershipKind);
2712
+ var->diagnose (diag::invalid_ownership_is_let, ownershipKind);
2714
2713
attr->setInvalid ();
2715
2714
}
2716
2715
@@ -2722,10 +2721,8 @@ Type TypeChecker::checkReferenceOwnershipAttr(VarDecl *var, Type type,
2722
2721
if (var->getAttrs ().hasAttribute <IBOutletAttr>())
2723
2722
break ;
2724
2723
2725
- auto diag = diagnose (var->getStartLoc (),
2726
- diag::invalid_ownership_not_optional,
2727
- ownershipKind,
2728
- OptionalType::get (type));
2724
+ auto diag = var->diagnose (diag::invalid_ownership_not_optional,
2725
+ ownershipKind, OptionalType::get (type));
2729
2726
auto typeRange = var->getTypeSourceRangeForDiagnostics ();
2730
2727
if (type->hasSimpleTypeRepr ()) {
2731
2728
diag.fixItInsertAfter (typeRange.End , " ?" );
@@ -2750,36 +2747,37 @@ Type TypeChecker::checkReferenceOwnershipAttr(VarDecl *var, Type type,
2750
2747
D = diag::invalid_ownership_protocol_type;
2751
2748
}
2752
2749
2753
- diagnose ( var->getStartLoc (), D, ownershipKind, underlyingType);
2750
+ var->diagnose ( D, ownershipKind, underlyingType);
2754
2751
attr->setInvalid ();
2755
2752
}
2756
2753
2757
2754
ClassDecl *underlyingClass = underlyingType->getClassOrBoundGenericClass ();
2758
2755
if (underlyingClass && underlyingClass->isIncompatibleWithWeakReferences ()) {
2759
- diagnose (attr->getLocation (),
2760
- diag::invalid_ownership_incompatible_class,
2761
- underlyingType, ownershipKind)
2762
- .fixItRemove (attr->getRange ());
2756
+ Diags
2757
+ .diagnose (attr->getLocation (),
2758
+ diag::invalid_ownership_incompatible_class, underlyingType,
2759
+ ownershipKind)
2760
+ .fixItRemove (attr->getRange ());
2763
2761
attr->setInvalid ();
2764
2762
}
2765
2763
2766
2764
auto PDC = dyn_cast<ProtocolDecl>(dc);
2767
2765
if (PDC && !PDC->isObjC ()) {
2768
2766
// Ownership does not make sense in protocols, except for "weak" on
2769
2767
// properties of Objective-C protocols.
2770
- auto D = Context .isSwiftVersionAtLeast (5 )
2771
- ? diag::ownership_invalid_in_protocols
2772
- : diag::ownership_invalid_in_protocols_compat_warning;
2773
- diagnose (attr->getLocation (), D, ownershipKind)
2774
- .fixItRemove (attr->getRange ());
2768
+ auto D = var-> getASTContext () .isSwiftVersionAtLeast (5 )
2769
+ ? diag::ownership_invalid_in_protocols
2770
+ : diag::ownership_invalid_in_protocols_compat_warning;
2771
+ Diags. diagnose (attr->getLocation (), D, ownershipKind)
2772
+ .fixItRemove (attr->getRange ());
2775
2773
attr->setInvalid ();
2776
2774
}
2777
2775
2778
2776
if (attr->isInvalid ())
2779
2777
return type;
2780
2778
2781
2779
// Change the type to the appropriate reference storage type.
2782
- return ReferenceStorageType::get (type, ownershipKind, Context );
2780
+ return ReferenceStorageType::get (type, ownershipKind, var-> getASTContext () );
2783
2781
}
2784
2782
2785
2783
Optional<Diag<>>
0 commit comments