File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -2535,7 +2535,19 @@ namespace {
2535
2535
ConstraintKind::CheckedCast, subPatternType, castType,
2536
2536
locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2537
2537
2538
- return setType (subPatternType);
2538
+ // Allow `is` pattern to infer type from context which is then going
2539
+ // to be propaged down to its sub-pattern via conversion. This enables
2540
+ // correct handling of patterns like `_ as Foo` where `_` would
2541
+ // get a type of `Foo` but `is` pattern enclosing it could still be
2542
+ // inferred from enclosing context.
2543
+ auto isType = CS.createTypeVariable (
2544
+ CS.getConstraintLocator (
2545
+ locator.withPathElement (LocatorPathElt::PatternMatch (pattern))),
2546
+ TVO_CanBindToNoEscape);
2547
+ CS.addConstraint (
2548
+ ConstraintKind::Conversion, subPatternType, isType,
2549
+ locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2550
+ return setType (isType);
2539
2551
}
2540
2552
2541
2553
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