Skip to content

Commit 11a0e88

Browse files
committed
[CS] Fix IgnoreUnresolvedPatternVar::diagnose such that it returns false
Returning `true` is wrong here as we could have the error diagnosed by another fix, which if not handled, would lead to us crashing as we assume we diagnosed the issue. Instead, return `false`, allowing us to at least bail with a bad error rather than a crash. We still need to go through and update argument list diagnostic logic to handle patterns, but I'm leaving that as future work for now. rdar://107724970 rdar://107651291
1 parent 4f4e914 commit 11a0e88

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

lib/Sema/CSFix.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,9 +2139,10 @@ IgnoreResultBuilderWithReturnStmts::create(ConstraintSystem &cs, Type builderTy,
21392139

21402140
bool IgnoreUnresolvedPatternVar::diagnose(const Solution &solution,
21412141
bool asNote) const {
2142-
// Not being able to infer the type of a pattern should already have been
2143-
// diagnosed on the pattern's initializer or as a structural issue of the AST.
2144-
return true;
2142+
// An unresolved AnyPatternDecl means there was some issue in the match
2143+
// that means we couldn't infer the pattern. We don't have a diagnostic to
2144+
// emit here, the failure should be diagnosed by the fix for expression.
2145+
return false;
21452146
}
21462147

21472148
IgnoreUnresolvedPatternVar *

test/Constraints/rdar107651291.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// rdar://107651291 – Make sure we don't crash
4+
func foo(xs: [String: [String]], ys: [String: [String]]) {
5+
for (key, value) in xs {
6+
guard let ys = ys.first(where: { $0.key == key }) else { return }
7+
for (a, b) in zip(xs, ys) {}
8+
// expected-error@-1 {{type 'Dictionary<String, [String]>.Element' (aka '(key: String, value: Array<String>)') cannot conform to 'Sequence'}}
9+
// expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
10+
// expected-note@-3 {{required by referencing instance method 'next()'}}
11+
}
12+
}

test/Constraints/rdar107724970.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// rdar://107724970 – Make sure we don't crash.
4+
enum E {
5+
case e(Int)
6+
}
7+
func foo(_ x: E) {
8+
// FIXME: We need to handle pattern arguments in a bunch of places in argument
9+
// list diagnostic logic.
10+
// https://github.com/apple/swift/issues/65062
11+
let fn = { // expected-error {{unable to infer closure type in the current context}}
12+
switch x {
13+
case E.e(_, _):
14+
break
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)