Skip to content

Commit d5fcf1a

Browse files
authored
Merge pull request #24274 from theblixguy/fix/computed-prop-fix-it-lazy
[CSDiagnostics] Removes lazy when applying computed property fix-it
2 parents 9850150 + 20cfa14 commit d5fcf1a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,10 @@ void ContextualFailure::tryComputedPropertyFixIts(Expr *expr) const {
14741474
if (VD->isLet()) {
14751475
diag.fixItReplace(PBD->getStartLoc(), getTokenText(tok::kw_var));
14761476
}
1477+
1478+
if (auto lazyAttr = VD->getAttrs().getAttribute<LazyAttr>()) {
1479+
diag.fixItRemove(lazyAttr->getRange());
1480+
}
14771481
}
14781482
}
14791483
}

test/decl/var/properties.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,3 +1306,8 @@ class SR_9267_C {
13061306
class SR_9267_C2 {
13071307
let SR_9267_prop_3: Int = { return 0 } // expected-error {{function produces expected type 'Int'; did you mean to call it with '()'?}} // expected-note {{Remove '=' to make 'SR_9267_prop_3' a computed property}}{{3-6=var}}{{27-29=}}
13081308
}
1309+
1310+
class LazyPropInClass {
1311+
lazy var foo: Int = { return 0 } // expected-error {{function produces expected type 'Int'; did you mean to call it with '()'?}}
1312+
// expected-note@-1 {{Remove '=' to make 'foo' a computed property}}{{21-23=}}{{3-8=}}
1313+
}

0 commit comments

Comments
 (0)