[Sema] Remove some hasError checks for typeCheckPattern

These shouldn't be necessary anymore, we should be able to handle
ErrorType patterns.
This commit is contained in:
Hamish Knight
2025-09-28 14:57:52 +01:00
parent 0c58138a42
commit 2c0ea134a9
5 changed files with 6 additions and 21 deletions

View File

@@ -4823,12 +4823,6 @@ generateForEachPreambleConstraints(ConstraintSystem &cs,
return std::nullopt;
target.setPattern(pattern);
auto contextualPattern = ContextualPattern::forRawPattern(pattern, dc);
if (TypeChecker::typeCheckPattern(contextualPattern)->hasError()) {
return std::nullopt;
}
if (isa<PackExpansionExpr>(forEachExpr)) {
auto *expansion = cast<PackExpansionExpr>(forEachExpr);
@@ -4996,10 +4990,6 @@ bool ConstraintSystem::generateConstraints(
ContextualPattern::forPatternBindingDecl(patternBinding, index);
Type patternType = TypeChecker::typeCheckPattern(contextualPattern);
// Fail early if pattern couldn't be type-checked.
if (!patternType || patternType->hasError())
return true;
auto *init = patternBinding->getInit(index);
if (!init && patternBinding->isDefaultInitializable(index) &&

View File

@@ -905,10 +905,6 @@ typeCheckPatternBindingStmtConditionElement(StmtConditionElement &elt,
// provide type information.
auto contextualPattern = ContextualPattern::forRawPattern(pattern, dc);
Type patternType = TypeChecker::typeCheckPattern(contextualPattern);
if (patternType->hasError()) {
typeCheckPatternFailed();
return true;
}
// If the pattern didn't get a type, it's because we ran into some
// unknown types along the way. We'll need to check the initializer.

View File

@@ -451,12 +451,6 @@ const PatternBindingEntry *PatternBindingEntryRequest::evaluate(
auto contextualPattern =
ContextualPattern::forPatternBindingDecl(binding, entryNumber);
Type patternType = TypeChecker::typeCheckPattern(contextualPattern);
if (patternType->hasError()) {
swift::setBoundVarsTypeError(pattern, Context);
binding->setInvalid();
pattern->setType(ErrorType::get(Context));
return &pbe;
}
llvm::SmallVector<VarDecl *, 2> vars;
binding->getPattern(entryNumber)->collectVariables(vars);

View File

@@ -472,7 +472,9 @@ do {
}
class testStdlibType {
let _: Array // expected-error {{reference to generic type 'Array' requires arguments in <...>}} {{15-15=<Any>}}
let _: Array
// expected-error@-1 {{reference to generic type 'Array' requires arguments in <...>}} {{15-15=<Any>}}
// expected-error@-2 {{property declaration does not bind any variables}}
}
// rdar://problem/32697033

View File

@@ -840,4 +840,7 @@ func testUndefinedInClosureVar() {
_ = {
var x: Undefined // expected-error {{cannot find type 'Undefined' in scope}}
}
_ = {
for x: Undefined in [0] {} // expected-error {{cannot find type 'Undefined' in scope}}
}
}