Skip to content

Commit 608cfcd

Browse files
authored
Use String(reflecting:) instead of _typeName(_:qualified:) to get the fully-qualified names of types. (#325)
We were directly using the Swift standard library function `_typeName(_:qualified:)` to get the fully-qualified names of types, but `String(reflecting:)` does this for us and is supported API. This PR switches us over to the API. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 5883682 commit 608cfcd

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Sources/Testing/Parameterization/TypeInfo.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ extension TypeInfo {
9292
public var fullyQualifiedNameComponents: [String] {
9393
switch _kind {
9494
case let .type(type):
95-
var result = _typeName(type, qualified: true)
95+
var result = String(reflecting: type)
9696
.split(separator: ".")
9797
.map(String.init)
9898

9999
// If a type is extended in another module and then referenced by name,
100-
// its name according to the _typeName(_:qualified:) SPI will be prefixed
101-
// with "(extension in MODULE_NAME):". For our purposes, we never want to
100+
// its name according to the String(reflecting:) API will be prefixed with
101+
// "(extension in MODULE_NAME):". For our purposes, we never want to
102102
// preserve that prefix.
103103
if let firstComponent = result.first, firstComponent.starts(with: "(extension in ") {
104104
result[0] = String(firstComponent.split(separator: ":", maxSplits: 1).last!)

Tests/TestingTests/TypeInfoTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct TypeInfoTests {
4141
}
4242

4343
@Test func typeNameInExtensionIsMungedCorrectly() {
44-
#expect(_typeName(String.NestedType.self, qualified: true) == "(extension in TestingTests):Swift.String.NestedType")
44+
#expect(String(reflecting: String.NestedType.self) == "(extension in TestingTests):Swift.String.NestedType")
4545
#expect(TypeInfo(describing: String.NestedType.self).fullyQualifiedName == "Swift.String.NestedType")
4646
}
4747

0 commit comments

Comments
 (0)