Closed
Description
Description
The following code defines a wrapper struct around a value and uses @dynamicMemberLookup
to expose access to the underlying value:
@dynamicMemberLookup
struct Wrapper<Value> {
let value: Value
subscript<OtherValue>(dynamicMember keyPath: KeyPath<Value, OtherValue>) -> OtherValue {
self.value[keyPath: keyPath]
}
}
In Swift 5.8, if we try to access a key path's debugDescription
on Wrapper
that goes through the dynamic member, we get a runtime crash:
let kp = \Wrapper<String>.count
print(kp.debugDescription) // 🛑 Bad access
Steps to reproduce
Run the above code in any Swift environment.
Expected behavior
It should print out something like "\Wrapper<String>.count"
.
Environment
- swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
- Xcode 14.3, Build version 14E222b
- Deployment target: iOS 16.4
Metadata
Metadata
Assignees
Labels
Feature → attributes: the @dynamicMemberLookup attributeArea → standard library: The `AnyKeyPath` typeArea → standard library: The `CustomDebugStringConvertible` protocolFeature: Declaration and type attributesA deviation from expected or documented behavior. Also: expected but undesirable behavior.The Swift compiler itselfBug: A crash, i.e., an abnormal termination of softwareFeature: declarationsArea → compiler: The `libswiftDemangling` libraryFeature: generic declarations and typesFeature: key paths (both native and Objective-C)Area: Standard library umbrellaFeature: Subscript declarations