Skip to content

Sema: Fix a failure to emit a diagnostic in pre-check expression pass #12574

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
Oct 23, 2017
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
9 changes: 8 additions & 1 deletion lib/Sema/TypeCheckConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,14 @@ resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *DC) {
// FIXME: If we reach this point, the program we're being handed is likely
// very broken, but it's still conceivable that this may happen due to
// invalid shadowed declarations.
// llvm_unreachable("Can't represent lookup result");
//
// Make sure we emit a diagnostic, since returning an ErrorExpr without
// producing one will break things downstream.
diagnose(Loc, diag::ambiguous_decl_ref, Name);
for (auto Result : Lookup) {
auto *Decl = Result.getValueDecl();
diagnose(Decl, diag::decl_declared_here, Decl->getFullName());
}
return new (Context) ErrorExpr(UDRE->getSourceRange());
}

Expand Down
14 changes: 14 additions & 0 deletions test/Constraints/diag_ambiguities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,17 @@ struct SR3715 {
take([overloaded]) // no error
}
}

// rdar://35116378 - Here the ambiguity is in the pre-check pass; make sure
// we emit a diagnostic instead of crashing.
struct Movie {}

class MoviesViewController {
typealias itemType = Movie // expected-note {{'itemType' declared here}}
let itemType = [Movie].self // expected-note {{'itemType' declared here}}
var items: [Movie] = [Movie]()

func loadData() {
_ = itemType // expected-error {{ambiguous use of 'itemType'}}
}
}