Skip to content

Sema: Fix crash in IfExpr diagnostics #16166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8468,6 +8468,11 @@ Solution::convertBooleanTypeToBuiltinI1(Expr *expr,

auto type = cs.getType(expr);

// We allow UnresolvedType <c $T for all $T, so we might end up here
// in diagnostics. Just bail out.
if (type->is<UnresolvedType>())
return expr;

// Look for the builtin name. If we don't have it, we need to call the
// general name via the witness table.
NameLookupOptions lookupOptions = defaultMemberLookupOptions;
Expand Down
22 changes: 22 additions & 0 deletions test/Constraints/if_expr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,25 @@ let ib: Bool! = false
let eb: Bool? = .some(false)
let conditional = ib ? "Broken" : "Heart" // should infer Bool!
let conditional = eb ? "Broken" : "Heart" // expected-error {{value of optional type 'Bool?' not unwrapped; did you mean to use '!' or '?'?}}

// <rdar://problem/39586166> - crash when IfExpr has UnresolvedType in condition
struct Delegate {
var shellTasks: [ShellTask]
}

extension Array {
subscript(safe safe: Int) -> Element? { // expected-note {{found this candidate}}
get { }
set { }
}
}

struct ShellTask {
var commandLine: [String]
}

let delegate = Delegate(shellTasks: [])
_ = delegate.shellTasks[safe: 0]?.commandLine.compactMap({ $0.asString.hasPrefix("") ? $0 : nil }).count ?? 0
// expected-error@-1 {{ambiguous reference to member 'subscript'}}

// FIXME: Horrible diagnostic, but at least we no longer crash