Skip to content

Commit 396a93b

Browse files
committed
[Diagnostics] Ignore warnings while diagnosing ambiguities
Warnings cannot lead to failures or ambiguity so let's remove them from consideration when attempting to diagnose ambiguity potentially caused by the same fix appearing in different solutions. Resolves: rdar://81228501
1 parent 54a7577 commit 396a93b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3989,8 +3989,14 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
39893989

39903990
llvm::SmallSetVector<FixInContext, 4> fixes;
39913991
for (auto &solution : solutions) {
3992-
for (auto *fix : solution.Fixes)
3992+
for (auto *fix : solution.Fixes) {
3993+
// Ignore warnings in favor of actual error fixes,
3994+
// because they are not the source of ambiguity/failures.
3995+
if (fix->isWarning())
3996+
continue;
3997+
39933998
fixes.insert({&solution, fix});
3999+
}
39944000
}
39954001

39964002
llvm::MapVector<ConstraintLocator *, SmallVector<FixInContext, 4>>

test/Constraints/closures.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,3 +1163,13 @@ func rdar78917861() {
11631163
}()
11641164
}
11651165
}
1166+
1167+
// rdar://81228501 - type-checker crash due to applied invalid solution
1168+
func test(arr: [[Int]]) {
1169+
struct A {
1170+
init(arg: [Int]) {}
1171+
}
1172+
1173+
arr.map { ($0 as? [Int]).map { A($0) } } // expected-error {{missing argument label 'arg:' in call}} {{36-36=arg: }}
1174+
// expected-warning@-1 {{conditional cast from '[Int]' to '[Int]' always succeeds}}
1175+
}

0 commit comments

Comments
 (0)