Skip to content

Commit a3bda75

Browse files
committed
Mark failed initializers as errors
When the initialization expression on a variable declaration fails, give it an ErrorType so Swift does not redundantly diagnose its un-inferrable type. Fixes: * test/NameBinding/stdlib.swift * test/decl/typealias/protocol.swift Would also have redundantly fixed the same tests as 2e875e7e, but the targeted solution there is cleaner.
1 parent 252fa1b commit a3bda75

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,6 +2099,10 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
20992099
contextualPurpose,
21002100
flags,
21012101
&listener);
2102+
2103+
if (hadError && !initializer->getType()) {
2104+
initializer->setType(ErrorType::get(Context));
2105+
}
21022106

21032107
if (hadError && !pattern->hasType()) {
21042108
pattern->setType(ErrorType::get(Context));

0 commit comments

Comments
 (0)