File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -7543,6 +7543,7 @@ ConstraintSystem::simplifyKeyPathConstraint(
7543
7543
} capability = Writable;
7544
7544
7545
7545
bool anyComponentsUnresolved = false ;
7546
+ bool didOptionalChain = false ;
7546
7547
7547
7548
for (unsigned i : indices (keyPath->getComponents ())) {
7548
7549
auto &component = keyPath->getComponents ()[i];
@@ -7642,26 +7643,27 @@ ConstraintSystem::simplifyKeyPathConstraint(
7642
7643
}
7643
7644
7644
7645
case KeyPathExpr::Component::Kind::OptionalChain:
7645
- // Optional chains force the entire key path to be read-only.
7646
- capability = ReadOnly;
7647
- goto done;
7646
+ didOptionalChain = true ;
7647
+ break ;
7648
7648
7649
7649
case KeyPathExpr::Component::Kind::OptionalForce:
7650
7650
// Forcing an optional preserves its lvalue-ness.
7651
7651
break ;
7652
7652
7653
7653
case KeyPathExpr::Component::Kind::OptionalWrap:
7654
- // An optional chain should already have forced the entire key path to
7655
- // be read-only.
7656
- assert (capability == ReadOnly);
7654
+ // An optional chain should already have been recorded.
7655
+ assert (didOptionalChain);
7657
7656
break ;
7658
7657
7659
7658
case KeyPathExpr::Component::Kind::TupleElement:
7660
7659
llvm_unreachable (" not implemented" );
7661
7660
break ;
7662
7661
}
7663
7662
}
7664
- done:
7663
+
7664
+ // Optional chains force the entire key path to be read-only.
7665
+ if (didOptionalChain)
7666
+ capability = ReadOnly;
7665
7667
7666
7668
// Resolve the type.
7667
7669
NominalTypeDecl *kpDecl;
Original file line number Diff line number Diff line change @@ -811,6 +811,16 @@ func test_keypath_with_method_refs() {
811
811
let _ = \A . Type. faz. bar // expected-error {{key path cannot refer to static method 'faz()'}}
812
812
}
813
813
814
+ // SR-12519: Compiler crash on invalid method reference in key path.
815
+ protocol Zonk {
816
+ func wargle( )
817
+ }
818
+ typealias Blatz = ( gloop: String , zoop: Zonk ? )
819
+
820
+ func sr12519( fleep: [ Blatz ] ) {
821
+ fleep. compactMap ( \. zoop? . wargle) // expected-error {{key path cannot refer to instance method 'wargle()'}}
822
+ }
823
+
814
824
// SR-10467 - Argument type 'KeyPath<String, Int>' does not conform to expected type 'Any'
815
825
func test_keypath_in_any_context( ) {
816
826
func foo( _: Any ) { }
You can’t perform that action at this time.
0 commit comments