Skip to content

Commit 7280261

Browse files
authored
Merge pull request #3396 from benlangmuir/optional-objc-fixit
2 parents 5f47048 + b7086b7 commit 7280261

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/AST/Decl.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,9 +1794,15 @@ bool ValueDecl::canInferObjCFromRequirement(ValueDecl *requirement) {
17941794

17951795
SourceLoc ValueDecl::getAttributeInsertionLoc(bool forModifier) const {
17961796
if (auto var = dyn_cast<VarDecl>(this)) {
1797-
if (auto pbd = var->getParentPatternBinding()) {
1798-
SourceLoc resultLoc = pbd->getAttrs().getStartLoc(forModifier);
1799-
return resultLoc.isValid() ? resultLoc : pbd->getStartLoc();
1797+
// [attrs] var ...
1798+
// The attributes are part of the VarDecl, but the 'var' is part of the PBD.
1799+
SourceLoc resultLoc = var->getAttrs().getStartLoc(forModifier);
1800+
if (resultLoc.isValid()) {
1801+
return resultLoc;
1802+
} else if (auto pbd = var->getParentPatternBinding()) {
1803+
return pbd->getStartLoc();
1804+
} else {
1805+
return var->getStartLoc();
18001806
}
18011807
}
18021808

test/decl/protocol/req/optional.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ protocol optErrorProtocol {
224224

225225
@objc protocol optObjcAttributeProtocol {
226226
optional func foo(_ x: Int) // expected-error{{'optional' requirements are an Objective-C compatibility feature; add '@objc'}}{{3-3=@objc }}
227+
optional var bar: Int { get } // expected-error{{'optional' requirements are an Objective-C compatibility feature; add '@objc'}}{{3-3=@objc }}
227228
optional associatedtype Assoc // expected-error{{'optional' modifier cannot be applied to this declaration}} {{3-12=}}
228229
}
229230

0 commit comments

Comments
 (0)