Skip to content

Commit bffd21f

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

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
@@ -2388,12 +2388,7 @@ namespace {
23882388
bool bindPatternVarsOneWay,
23892389
PatternBindingDecl *patternBinding = nullptr,
23902390
unsigned patternBindingIndex = 0) {
2391-
// If there's no pattern, then we have an unknown subpattern. Create a
2392-
// type variable.
2393-
if (!pattern) {
2394-
return CS.createTypeVariable(CS.getConstraintLocator(locator),
2395-
TVO_CanBindToNoEscape);
2396-
}
2391+
assert(pattern);
23972392

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

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

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

0 commit comments

Comments
 (0)