Skip to content

Commit a6e8066

Browse files
committed
Merge remote-tracking branch 'github/master' into HEAD
2 parents de3390f + 65da7f6 commit a6e8066

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lib/Sema/CSGen.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,12 +2282,17 @@ namespace {
22822282

22832283
return setType(ParenType::get(CS.getASTContext(), underlyingType));
22842284
}
2285-
case PatternKind::Var:
2285+
case PatternKind::Var: {
2286+
auto *subPattern = cast<VarPattern>(pattern)->getSubPattern();
2287+
auto type = getTypeForPattern(subPattern, locator, externalPatternType,
2288+
bindPatternVarsOneWay);
2289+
2290+
if (!type)
2291+
return Type();
2292+
22862293
// Var doesn't affect the type.
2287-
return setType(
2288-
getTypeForPattern(
2289-
cast<VarPattern>(pattern)->getSubPattern(), locator,
2290-
externalPatternType, bindPatternVarsOneWay));
2294+
return setType(type);
2295+
}
22912296

22922297
case PatternKind::Any: {
22932298
return setType(
@@ -3925,7 +3930,9 @@ static bool generateInitPatternConstraints(
39253930
pattern, locator, target.shouldBindPatternVarsOneWay(),
39263931
target.getInitializationPatternBindingDecl(),
39273932
target.getInitializationPatternBindingIndex());
3928-
assert(patternType && "All patterns have a type");
3933+
3934+
if (!patternType)
3935+
return true;
39293936

39303937
if (auto wrappedVar = target.getInitializationWrappedVar()) {
39313938
Type propertyType = generateWrappedPropertyTypeConstraints(

test/Constraints/patterns.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,14 @@ func rdar63510989() {
507507
// expected-warning@-1 {{immutable value 'v' was never used; consider replacing with '_' or removing it}}
508508
}
509509
}
510+
511+
// rdar://problem/64157451 - compiler crash when using undefined type in pattern
512+
func rdar64157451() {
513+
enum E {
514+
case foo(Int)
515+
}
516+
517+
func test(e: E) {
518+
if case .foo(let v as DoeNotExist) = e {} // expected-error {{cannot find type 'DoeNotExist' in scope}}
519+
}
520+
}

0 commit comments

Comments
 (0)