Skip to content

Commit 54c0fd4

Browse files
xedinLucianoPAlmeida
authored andcommitted
Merge pull request #40480 from LucianoPAlmeida/SR-15562-fail-diag
[SR-15562] [Sema] Do not consider warning fixes for non-augmenting fix recording
1 parent 2668223 commit 54c0fd4

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11657,9 +11657,16 @@ bool ConstraintSystem::recordFix(ConstraintFix *fix, unsigned impact) {
1165711657
// current anchor or, in case of anchor being an expression, any of
1165811658
// its sub-expressions.
1165911659
llvm::SmallDenseSet<ASTNode> anchors;
11660-
for (const auto *fix : Fixes)
11661-
anchors.insert(fix->getAnchor());
11660+
for (const auto *fix : Fixes) {
11661+
// Warning fixes shouldn't be considered because even if
11662+
// such fix is recorded at that anchor this should not
11663+
// have any affect in the recording of any other fix.
11664+
if (fix->isWarning())
11665+
continue;
1166211666

11667+
anchors.insert(fix->getAnchor());
11668+
}
11669+
1166311670
bool found = false;
1166411671
if (auto *expr = getAsExpr(anchor)) {
1166511672
forEachExpr(expr, [&](Expr *subExpr) -> Expr * {

test/Constraints/casts.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,3 +651,14 @@ struct SR15281_SC {
651651
a.flatMap(SR15281_CC.init(a:)) // expected-error{{cannot convert return expression of type 'SR15281_CC?' to return type 'SR15281_BC'}} {{35-35=!}}
652652
}
653653
}
654+
655+
// SR-15562
656+
func test_SR_15562() {
657+
let foo: [Int: Int] = [:]
658+
let bar = [1, 2, 3, 4]
659+
660+
for baz in bar {
661+
foo[baz] as! Int += 1 // expected-warning{{forced cast from 'Int?' to 'Int' only unwraps optionals; did you mean to use '!'?}}
662+
// expected-error@-1{{left side of mutating operator has immutable type 'Int'}}
663+
}
664+
}

0 commit comments

Comments
 (0)