Skip to content

Commit bca1928

Browse files
committed
[CS] Remove null pattern handling from getTypeForPattern
Push the only null case that can occur up into the caller.
1 parent d02328e commit bca1928

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

lib/Sema/CSGen.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,12 +2387,7 @@ namespace {
23872387
bool bindPatternVarsOneWay,
23882388
PatternBindingDecl *patternBinding = nullptr,
23892389
unsigned patternBindingIndex = 0) {
2390-
// If there's no pattern, then we have an unknown subpattern. Create a
2391-
// type variable.
2392-
if (!pattern) {
2393-
return CS.createTypeVariable(CS.getConstraintLocator(locator),
2394-
TVO_CanBindToNoEscape);
2395-
}
2390+
assert(pattern);
23962391

23972392
// Local function that must be called for each "return" throughout this
23982393
// function, to set the type of the pattern.
@@ -4232,16 +4227,18 @@ bool ConstraintSystem::generateWrappedPropertyTypeConstraints(
42324227
static bool generateInitPatternConstraints(ConstraintSystem &cs,
42334228
SyntacticElementTarget target,
42344229
Expr *initializer) {
4235-
auto pattern = target.getInitializationPattern();
42364230
auto locator = cs.getConstraintLocator(
42374231
initializer, LocatorPathElt::ContextualType(CTP_Initialization));
4238-
Type patternType = cs.generateConstraints(
4239-
pattern, locator, target.shouldBindPatternVarsOneWay(),
4240-
target.getInitializationPatternBindingDecl(),
4241-
target.getInitializationPatternBindingIndex());
42424232

4243-
if (!patternType)
4244-
return true;
4233+
Type patternType;
4234+
if (auto pattern = target.getInitializationPattern()) {
4235+
patternType = cs.generateConstraints(
4236+
pattern, locator, target.shouldBindPatternVarsOneWay(),
4237+
target.getInitializationPatternBindingDecl(),
4238+
target.getInitializationPatternBindingIndex());
4239+
} else {
4240+
patternType = cs.createTypeVariable(locator, TVO_CanBindToNoEscape);
4241+
}
42454242

42464243
if (auto wrappedVar = target.getInitializationWrappedVar())
42474244
return cs.generateWrappedPropertyTypeConstraints(

0 commit comments

Comments
 (0)