Skip to content

Commit f440432

Browse files
committed
[Runtime] Fix debugDescription of .self keypaths.
AnyKeyPath's debugDescription assumes there's always at least one component, but `\Type.self` produces an empty keypath. Special-case the empty case to display a `.self` component. rdar://103237845
1 parent c914579 commit f440432

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

stdlib/public/core/KeyPath.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3934,7 +3934,8 @@ extension AnyKeyPath: CustomDebugStringConvertible {
39343934
return withBuffer {
39353935
var buffer = $0
39363936
if buffer.data.isEmpty {
3937-
_internalInvariantFailure("key path has no components")
3937+
description.append(".self")
3938+
return description
39383939
}
39393940
var valueType: Any.Type = Self.rootType
39403941
while true {

test/Interpreter/keypath.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,5 @@ print(\Controller[int: 0, str: "", 0])
9393
print(\Controller.thirdLabel)
9494
// CHECK: {{\\Controller\.subscript\(\)|\\Controller\.<computed 0x.* \(Int\)>}}
9595
print(\Controller.[])
96+
// CHECK: \Controller.self
97+
print(\Controller.self)

0 commit comments

Comments
 (0)