Skip to content

Commit 8bd0e9f

Browse files
authored
Merge pull request #24284 from theblixguy/fix/computed-prop-fix-it-lazy-5.1
[5.1] [CSDiagnostics] Removes lazy when applying computed property fix-it
2 parents 4fe9192 + a05b0bd commit 8bd0e9f

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
@@ -1470,6 +1470,10 @@ void ContextualFailure::tryComputedPropertyFixIts(Expr *expr) const {
14701470
if (VD->isLet()) {
14711471
diag.fixItReplace(PBD->getStartLoc(), getTokenText(tok::kw_var));
14721472
}
1473+
1474+
if (auto lazyAttr = VD->getAttrs().getAttribute<LazyAttr>()) {
1475+
diag.fixItRemove(lazyAttr->getRange());
1476+
}
14731477
}
14741478
}
14751479
}

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)