File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -2545,7 +2545,17 @@ namespace {
2545
2545
ConstraintKind::CheckedCast, subPatternType, castType,
2546
2546
locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2547
2547
2548
- return setType (subPatternType);
2548
+ // Allow `is` pattern to infer type from context which is then going
2549
+ // to be propaged down to its sub-pattern via conversion. This enables
2550
+ // correct handling of patterns like `_ as Foo` where `_` would
2551
+ // get a type of `Foo` but `is` pattern enclosing it could still be
2552
+ // inferred from enclosing context.
2553
+ auto isType = CS.createTypeVariable (CS.getConstraintLocator (pattern),
2554
+ TVO_CanBindToNoEscape);
2555
+ CS.addConstraint (
2556
+ ConstraintKind::Conversion, subPatternType, isType,
2557
+ locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2558
+ return setType (isType);
2549
2559
}
2550
2560
2551
2561
case PatternKind::Bool:
Original file line number Diff line number Diff line change @@ -478,3 +478,20 @@ func rdar_60048356() {
478
478
}
479
479
}
480
480
}
481
+
482
+ // rdar://problem/63510989 - valid pattern doesn't type-check
483
+ func rdar63510989( ) {
484
+ enum Value : P {
485
+ func p( ) { }
486
+ }
487
+
488
+ enum E {
489
+ case foo( P ? )
490
+ }
491
+
492
+ func test( e: E ) {
493
+ if case . foo( _ as Value ) = e { } // Ok
494
+ if case . foo( let v as Value ) = e { } // Ok
495
+ // expected-warning@-1 {{immutable value 'v' was never used; consider replacing with '_' or removing it}}
496
+ }
497
+ }
You can’t perform that action at this time.
0 commit comments