Skip to content

Commit 780ce15

Browse files
committed
Separate out move-only init otherwise a value may end up reporting its type as Any
1 parent 5182d9f commit 780ce15

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Sources/Testing/Parameterization/TypeInfo.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,22 @@ public struct TypeInfo: Sendable {
8888
///
8989
/// - Parameters:
9090
/// - value: The value whose type this instance should describe.
91-
init(describingTypeOf value: borrowing some ~Copyable) {
91+
init(describingTypeOf value: some Any) {
92+
#if !hasFeature(Embedded)
93+
let value = value as Any
94+
#endif
9295
let type = Swift.type(of: value)
9396
self.init(describing: type)
9497
}
98+
99+
/// Initialize an instance of this type describing the type of the specified
100+
/// value.
101+
///
102+
/// - Parameters:
103+
/// - value: The value whose type this instance should describe.
104+
init<T>(describingTypeOf value: borrowing T) where T: ~Copyable {
105+
self.init(describing: T.self)
106+
}
95107
}
96108

97109
// MARK: - Name

Tests/TestingTests/TypeInfoTests.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ struct TypeInfoTests {
122122
#expect(!TypeInfo(describing: String.self).isSwiftEnumeration)
123123
#expect(TypeInfo(describing: SomeEnum.self).isSwiftEnumeration)
124124
}
125+
126+
@Test func typeOfMoveOnlyValueIsInferred() {
127+
let value = MoveOnlyType()
128+
#expect(TypeInfo(describingTypeOf: value).unqualifiedName == "MoveOnlyType")
129+
}
125130
}
126131

127132
// MARK: - Fixtures
@@ -131,3 +136,5 @@ extension String {
131136
}
132137

133138
private enum SomeEnum {}
139+
140+
private struct MoveOnlyType: ~Copyable {}

0 commit comments

Comments
 (0)