Skip to content

Commit 5a90c4f

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

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
@@ -2427,12 +2427,7 @@ namespace {
24272427
bool bindPatternVarsOneWay,
24282428
PatternBindingDecl *patternBinding = nullptr,
24292429
unsigned patternBindingIndex = 0) {
2430-
// If there's no pattern, then we have an unknown subpattern. Create a
2431-
// type variable.
2432-
if (!pattern) {
2433-
return CS.createTypeVariable(CS.getConstraintLocator(locator),
2434-
TVO_CanBindToNoEscape);
2435-
}
2430+
assert(pattern);
24362431

24372432
// Local function that must be called for each "return" throughout this
24382433
// function, to set the type of the pattern.
@@ -4335,16 +4330,18 @@ bool ConstraintSystem::generateWrappedPropertyTypeConstraints(
43354330
static bool generateInitPatternConstraints(ConstraintSystem &cs,
43364331
SyntacticElementTarget target,
43374332
Expr *initializer) {
4338-
auto pattern = target.getInitializationPattern();
43394333
auto locator = cs.getConstraintLocator(
43404334
initializer, LocatorPathElt::ContextualType(CTP_Initialization));
4341-
Type patternType = cs.generateConstraints(
4342-
pattern, locator, target.shouldBindPatternVarsOneWay(),
4343-
target.getInitializationPatternBindingDecl(),
4344-
target.getInitializationPatternBindingIndex());
43454335

4346-
if (!patternType)
4347-
return true;
4336+
Type patternType;
4337+
if (auto pattern = target.getInitializationPattern()) {
4338+
patternType = cs.generateConstraints(
4339+
pattern, locator, target.shouldBindPatternVarsOneWay(),
4340+
target.getInitializationPatternBindingDecl(),
4341+
target.getInitializationPatternBindingIndex());
4342+
} else {
4343+
patternType = cs.createTypeVariable(locator, TVO_CanBindToNoEscape);
4344+
}
43484345

43494346
if (auto wrappedVar = target.getInitializationWrappedVar())
43504347
return cs.generateWrappedPropertyTypeConstraints(

0 commit comments

Comments
 (0)