File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -2321,12 +2321,18 @@ namespace {
2321
2321
2322
2322
return setType (ParenType::get (CS.getASTContext (), underlyingType));
2323
2323
}
2324
- case PatternKind::Var:
2324
+ case PatternKind::Var: {
2325
+ auto *subPattern = cast<VarPattern>(pattern)->getSubPattern ();
2326
+ auto type = getTypeForPattern (subPattern, locator, externalPatternType,
2327
+ bindPatternVarsOneWay);
2328
+
2329
+ if (!type)
2330
+ return Type ();
2331
+
2325
2332
// Var doesn't affect the type.
2326
- return setType (
2327
- getTypeForPattern (
2328
- cast<VarPattern>(pattern)->getSubPattern (), locator,
2329
- externalPatternType, bindPatternVarsOneWay));
2333
+ return setType (type);
2334
+ }
2335
+
2330
2336
case PatternKind::Any: {
2331
2337
return setType (
2332
2338
CS.createTypeVariable (CS.getConstraintLocator (locator),
@@ -4235,7 +4241,9 @@ static bool generateInitPatternConstraints(
4235
4241
pattern, locator, target.shouldBindPatternVarsOneWay (),
4236
4242
target.getInitializationPatternBindingDecl (),
4237
4243
target.getInitializationPatternBindingIndex ());
4238
- assert (patternType && " All patterns have a type" );
4244
+
4245
+ if (!patternType)
4246
+ return true ;
4239
4247
4240
4248
if (auto wrappedVar = target.getInitializationWrappedVar ()) {
4241
4249
// Add an equal constraint between the pattern type and the
Original file line number Diff line number Diff line change @@ -495,3 +495,14 @@ func rdar63510989() {
495
495
// expected-warning@-1 {{immutable value 'v' was never used; consider replacing with '_' or removing it}}
496
496
}
497
497
}
498
+
499
+ // rdar://problem/64157451 - compiler crash when using undefined type in pattern
500
+ func rdar64157451( ) {
501
+ enum E {
502
+ case foo( Int )
503
+ }
504
+
505
+ func test( e: E ) {
506
+ if case . foo( let v as DoeNotExist ) = e { } // expected-error {{cannot find type 'DoeNotExist' in scope}}
507
+ }
508
+ }
You can’t perform that action at this time.
0 commit comments