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 {
25452545 ConstraintKind::CheckedCast, subPatternType, castType,
25462546 locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
25472547
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);
25492559 }
25502560
25512561 case PatternKind::Bool:
Original file line number Diff line number Diff line change @@ -478,3 +478,20 @@ func rdar_60048356() {
478478 }
479479 }
480480}
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