Skip to content

Commit 5c24021

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

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.
@@ -4230,16 +4225,18 @@ bool ConstraintSystem::generateWrappedPropertyTypeConstraints(
42304225
/// Generate additional constraints for the pattern of an initialization.
42314226
static bool generateInitPatternConstraints(
42324227
ConstraintSystem &cs, SolutionApplicationTarget target, Expr *initializer) {
4233-
auto pattern = target.getInitializationPattern();
42344228
auto locator = cs.getConstraintLocator(
42354229
initializer, LocatorPathElt::ContextualType(CTP_Initialization));
4236-
Type patternType = cs.generateConstraints(
4237-
pattern, locator, target.shouldBindPatternVarsOneWay(),
4238-
target.getInitializationPatternBindingDecl(),
4239-
target.getInitializationPatternBindingIndex());
42404230

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

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

0 commit comments

Comments
 (0)