Skip to content

Commit 240a02f

Browse files
authored
Merge pull request #12574 from slavapestov/pre-check-expr-error-expr
Sema: Fix a failure to emit a diagnostic in pre-check expression pass
2 parents d42ff7a + d23e2bc commit 240a02f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,14 @@ resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *DC) {
635635
// FIXME: If we reach this point, the program we're being handed is likely
636636
// very broken, but it's still conceivable that this may happen due to
637637
// invalid shadowed declarations.
638-
// llvm_unreachable("Can't represent lookup result");
638+
//
639+
// Make sure we emit a diagnostic, since returning an ErrorExpr without
640+
// producing one will break things downstream.
641+
diagnose(Loc, diag::ambiguous_decl_ref, Name);
642+
for (auto Result : Lookup) {
643+
auto *Decl = Result.getValueDecl();
644+
diagnose(Decl, diag::decl_declared_here, Decl->getFullName());
645+
}
639646
return new (Context) ErrorExpr(UDRE->getSourceRange());
640647
}
641648

test/Constraints/diag_ambiguities.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,17 @@ struct SR3715 {
5252
take([overloaded]) // no error
5353
}
5454
}
55+
56+
// rdar://35116378 - Here the ambiguity is in the pre-check pass; make sure
57+
// we emit a diagnostic instead of crashing.
58+
struct Movie {}
59+
60+
class MoviesViewController {
61+
typealias itemType = Movie // expected-note {{'itemType' declared here}}
62+
let itemType = [Movie].self // expected-note {{'itemType' declared here}}
63+
var items: [Movie] = [Movie]()
64+
65+
func loadData() {
66+
_ = itemType // expected-error {{ambiguous use of 'itemType'}}
67+
}
68+
}

0 commit comments

Comments
 (0)