File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -2199,13 +2199,14 @@ internal func _getKeyPathClassAndInstanceSizeFromPattern(
2199
2199
// Scan the pattern to figure out the dynamic capability of the key path.
2200
2200
// Start off assuming the key path is writable.
2201
2201
var capability : KeyPathKind = . value
2202
+ var didChain = false
2202
2203
2203
2204
let bufferPtr = pattern. advanced ( by: keyPathObjectHeaderSize)
2204
2205
var buffer = KeyPathBuffer ( base: bufferPtr)
2205
2206
var size = buffer. data. count + MemoryLayout< Int> . size
2206
2207
var alignmentMask = MemoryLayout < Int > . alignment - 1
2207
2208
2208
- scanComponents: while true {
2209
+ while true {
2209
2210
let header = buffer. pop ( RawKeyPathComponent . Header. self)
2210
2211
2211
2212
func popOffset( ) {
@@ -2290,8 +2291,8 @@ internal func _getKeyPathClassAndInstanceSizeFromPattern(
2290
2291
case . optionalChain,
2291
2292
. optionalWrap:
2292
2293
// Chaining always renders the whole key path read-only.
2293
- capability = . readOnly
2294
- break scanComponents
2294
+ didChain = true
2295
+ break
2295
2296
2296
2297
case . optionalForce:
2297
2298
// No effect.
@@ -2306,6 +2307,11 @@ internal func _getKeyPathClassAndInstanceSizeFromPattern(
2306
2307
alignment: MemoryLayout< Int> . alignment)
2307
2308
}
2308
2309
2310
+ // Chaining always renders the whole key path read-only.
2311
+ if didChain {
2312
+ capability = . readOnly
2313
+ }
2314
+
2309
2315
// Grab the class object for the key path type we'll end up with.
2310
2316
func openRoot< Root> ( _: Root . Type ) -> AnyKeyPath . Type {
2311
2317
func openLeaf< Leaf> ( _: Leaf . Type ) -> AnyKeyPath . Type {
Original file line number Diff line number Diff line change @@ -666,5 +666,25 @@ keyPath.test("subscripts") {
666
666
expectEqual ( base [ keyPath: ints_be] , ( 17 + 38 ) . bigEndian)
667
667
}
668
668
669
+ // SR-6096
670
+
671
+ protocol Protocol6096 { }
672
+ struct Value6096 < ValueType> { }
673
+ extension Protocol6096 {
674
+ var asString : String ? {
675
+ return self as? String
676
+ }
677
+ }
678
+ extension Value6096 where ValueType: Protocol6096 {
679
+ func doSomething( ) {
680
+ _ = \ValueType . asString? . endIndex
681
+ }
682
+ }
683
+ extension Int : Protocol6096 { }
684
+
685
+ keyPath. test ( " optional chaining component that needs generic instantiation " ) {
686
+ Value6096 < Int > ( ) . doSomething ( )
687
+ }
688
+
669
689
runAllTests ( )
670
690
You can’t perform that action at this time.
0 commit comments