mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[SR-8340]Improve fix-it for var and subscript in Protocol (#19660)
* [Parser] Improve fix-it for subscription in protocol * [Sema] Add fix-it for property in protocol https://bugs.swift.org/browse/SR-8340
This commit is contained in:
committed by
Rintaro Ishizaki
parent
6ab8389ecf
commit
f2bdce8251
@@ -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#> }");
|
||||
}
|
||||
}
|
||||
|
||||
setProtocolStorageImpl(TC, storage);
|
||||
|
||||
Reference in New Issue
Block a user