File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -2282,12 +2282,17 @@ namespace {
2282
2282
2283
2283
return setType (ParenType::get (CS.getASTContext (), underlyingType));
2284
2284
}
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
+
2286
2293
// 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
+ }
2291
2296
2292
2297
case PatternKind::Any: {
2293
2298
return setType (
@@ -3925,7 +3930,9 @@ static bool generateInitPatternConstraints(
3925
3930
pattern, locator, target.shouldBindPatternVarsOneWay (),
3926
3931
target.getInitializationPatternBindingDecl (),
3927
3932
target.getInitializationPatternBindingIndex ());
3928
- assert (patternType && " All patterns have a type" );
3933
+
3934
+ if (!patternType)
3935
+ return true ;
3929
3936
3930
3937
if (auto wrappedVar = target.getInitializationWrappedVar ()) {
3931
3938
Type propertyType = generateWrappedPropertyTypeConstraints (
Original file line number Diff line number Diff line change @@ -507,3 +507,14 @@ func rdar63510989() {
507
507
// expected-warning@-1 {{immutable value 'v' was never used; consider replacing with '_' or removing it}}
508
508
}
509
509
}
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
+ }
You can’t perform that action at this time.
0 commit comments