Skip to content

Commit 51d0721

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
1 parent c73cb3d commit 51d0721

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-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/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)