Skip to content

Commit f7f9073

Browse files
authored
Merge pull request #16166 from slavapestov/if-expr-crash
Sema: Fix crash in IfExpr diagnostics
2 parents ef6fc9f + e31bd92 commit f7f9073

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8468,6 +8468,11 @@ Solution::convertBooleanTypeToBuiltinI1(Expr *expr,
84688468

84698469
auto type = cs.getType(expr);
84708470

8471+
// We allow UnresolvedType <c $T for all $T, so we might end up here
8472+
// in diagnostics. Just bail out.
8473+
if (type->is<UnresolvedType>())
8474+
return expr;
8475+
84718476
// Look for the builtin name. If we don't have it, we need to call the
84728477
// general name via the witness table.
84738478
NameLookupOptions lookupOptions = defaultMemberLookupOptions;

test/Constraints/if_expr.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,25 @@ let ib: Bool! = false
6363
let eb: Bool? = .some(false)
6464
let conditional = ib ? "Broken" : "Heart" // should infer Bool!
6565
let conditional = eb ? "Broken" : "Heart" // expected-error {{value of optional type 'Bool?' not unwrapped; did you mean to use '!' or '?'?}}
66+
67+
// <rdar://problem/39586166> - crash when IfExpr has UnresolvedType in condition
68+
struct Delegate {
69+
var shellTasks: [ShellTask]
70+
}
71+
72+
extension Array {
73+
subscript(safe safe: Int) -> Element? { // expected-note {{found this candidate}}
74+
get { }
75+
set { }
76+
}
77+
}
78+
79+
struct ShellTask {
80+
var commandLine: [String]
81+
}
82+
83+
let delegate = Delegate(shellTasks: [])
84+
_ = delegate.shellTasks[safe: 0]?.commandLine.compactMap({ $0.asString.hasPrefix("") ? $0 : nil }).count ?? 0
85+
// expected-error@-1 {{ambiguous reference to member 'subscript'}}
86+
87+
// FIXME: Horrible diagnostic, but at least we no longer crash

0 commit comments

Comments
 (0)