Skip to content

Commit 57bfef0

Browse files
authored
Merge pull request #40480 from LucianoPAlmeida/SR-15562-fail-diag
[SR-15562] [Sema] Do not consider warning fixes for non-augmenting fix recording
2 parents 6a34f04 + 85246bc commit 57bfef0

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
@@ -11661,9 +11661,16 @@ bool ConstraintSystem::recordFix(ConstraintFix *fix, unsigned impact) {
1166111661
// current anchor or, in case of anchor being an expression, any of
1166211662
// its sub-expressions.
1166311663
llvm::SmallDenseSet<ASTNode> anchors;
11664-
for (const auto *fix : Fixes)
11665-
anchors.insert(fix->getAnchor());
11664+
for (const auto *fix : Fixes) {
11665+
// Warning fixes shouldn't be considered because even if
11666+
// such fix is recorded at that anchor this should not
11667+
// have any affect in the recording of any other fix.
11668+
if (fix->isWarning())
11669+
continue;
1166611670

11671+
anchors.insert(fix->getAnchor());
11672+
}
11673+
1166711674
bool found = false;
1166811675
if (auto *expr = getAsExpr(anchor)) {
1166911676
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)