Open
Description
Motivation
In Swift 5.8 there was a runtime crash in AnyKeyPath.debugDescription
that was fixed in #63305. However, the fix did the bare minimum to not crash, but the description of the key path is not great:
struct Foo {
subscript<A>(_ a: A) -> A { a }
}
print(\Foo.[1])
// "\Foo.<computed 0x0000000105129928 (Int)>"
Ideally it would be great if it could be printed like so:
print(\Foo.[1])
// "\Foo.[1]"
Further, if possible, it would also be really great if dynamic members could be given special treatment to be printed nicely:
@dynamicMemberLookup
struct Wrapper<Value> {
let value: Value
subscript<OtherValue>(dynamicMember keyPath: KeyPath<Value, OtherValue>) -> OtherValue {
self.value[keyPath: keyPath]
}
}
print(\Wrapper<String>.count)
// Should print "\Wrapper<String>.count"
// instead of "\Wrapper<String>.[dynamicMember: \String.count]"
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 itselfFeature: declarationsArea → compiler: The `libswiftDemangling` libraryFeature: generic declarations and typesFeature: key paths (both native and Objective-C)Area: Standard library umbrellaFeature: Subscript declarationsBug: Unexpected behavior or incorrect output