-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-8340]Improve fix-it for var and subscript in Protocol #19660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
67bf1a9
ee4f9b2
f0f33eb
7d35c95
f1d830a
9ca89e4
7ae9eb7
da9a19b
1ddfa58
fd5f3ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2023,11 +2023,21 @@ void swift::maybeAddAccessorsToStorage(TypeChecker &TC, | |
} else if (isa<ProtocolDecl>(dc)) { | ||
if (storage->hasStorage()) { | ||
auto var = cast<VarDecl>(storage); | ||
if (var->isLet()) | ||
|
||
if (var->isLet()) { | ||
TC.diagnose(var->getLoc(), | ||
diag::protocol_property_must_be_computed_var); | ||
else | ||
TC.diagnose(var->getLoc(), diag::protocol_property_must_be_computed); | ||
diag::protocol_property_must_be_computed_var) | ||
.fixItReplace(var->getParentPatternBinding()->getLoc(), "var") | ||
.fixItInsertAfter(var->getTypeLoc().getLoc(), " { get }"); | ||
} else { | ||
auto diag = TC.diagnose(var->getLoc(), diag::protocol_property_must_be_computed); | ||
auto braces = var->getBracesRange(); | ||
|
||
if (braces.isValid()) | ||
diag.fixItReplace(braces, "{ get <#set#> }"); | ||
else | ||
diag.fixItInsertAfter(var->getTypeLoc().getLoc(), " { get <#set#> }"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have test cases without type annotation? like: protocol P {
let foo
var bar
} If not, could you add them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
|
||
setProtocolStorageImpl(TC, storage); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, editor place holder (
<#...#>
) doesn't mean it's optional. Instead, we expect developers to replace it with actual code. But I admit it's handy in Xcode. (tab navigation, return key insertsset
, single del key removes the placeholder).@jrose-apple Any concern about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found it a little funny too, but I think it's reasonable. @nkcsgexi might also be a good person to ask.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it seems reasonable to me as well. One benefit of placeholder is being easy to remove or being made solid, which i believe is @mzp 's motivation here to include set as a placeholder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, the
<#set#>
was my idea, and that was my motivation.I made SR-8340.