Skip to content

Commit 7c514fc

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

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
@@ -2447,12 +2447,7 @@ namespace {
24472447
bool bindPatternVarsOneWay,
24482448
PatternBindingDecl *patternBinding = nullptr,
24492449
unsigned patternBindingIndex = 0) {
2450-
// If there's no pattern, then we have an unknown subpattern. Create a
2451-
// type variable.
2452-
if (!pattern) {
2453-
return CS.createTypeVariable(CS.getConstraintLocator(locator),
2454-
TVO_CanBindToNoEscape);
2455-
}
2450+
assert(pattern);
24562451

24572452
// Local function that must be called for each "return" throughout this
24582453
// function, to set the type of the pattern.
@@ -4365,16 +4360,18 @@ bool ConstraintSystem::generateWrappedPropertyTypeConstraints(
43654360
static bool generateInitPatternConstraints(ConstraintSystem &cs,
43664361
SyntacticElementTarget target,
43674362
Expr *initializer) {
4368-
auto pattern = target.getInitializationPattern();
43694363
auto locator = cs.getConstraintLocator(
43704364
initializer, LocatorPathElt::ContextualType(CTP_Initialization));
4371-
Type patternType = cs.generateConstraints(
4372-
pattern, locator, target.shouldBindPatternVarsOneWay(),
4373-
target.getInitializationPatternBindingDecl(),
4374-
target.getInitializationPatternBindingIndex());
43754365

4376-
if (!patternType)
4377-
return true;
4366+
Type patternType;
4367+
if (auto pattern = target.getInitializationPattern()) {
4368+
patternType = cs.generateConstraints(
4369+
pattern, locator, target.shouldBindPatternVarsOneWay(),
4370+
target.getInitializationPatternBindingDecl(),
4371+
target.getInitializationPatternBindingIndex());
4372+
} else {
4373+
patternType = cs.createTypeVariable(locator, TVO_CanBindToNoEscape);
4374+
}
43784375

43794376
if (auto wrappedVar = target.getInitializationWrappedVar())
43804377
return cs.generateWrappedPropertyTypeConstraints(

0 commit comments

Comments
 (0)