Skip to content

Commit c7dad6b

Browse files
Fix symbol link parsing bug for disambiguated subtraction operators (#739)
rdar://113870038 Co-authored-by: Pat Shaughnessy <[email protected]>
1 parent 4e9d7f8 commit c7dad6b

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

Sources/SwiftDocC/Infrastructure/Link Resolution/PathHierarchy+PathComponent.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ extension PathHierarchy {
108108
if let dashIndex = name.lastIndex(of: "-") {
109109
let kind = String(name[dashIndex...].dropFirst())
110110
let name = String(name[..<dashIndex])
111-
if let languagePrefix = knownLanguagePrefixes.first(where: { kind.starts(with: $0) }) {
112-
return PathComponent(full: full, name: name, kind: String(kind.dropFirst(languagePrefix.count)), hash: hash)
113-
} else {
111+
if knownSymbolKinds.contains(kind) {
114112
return PathComponent(full: full, name: name, kind: kind, hash: hash)
113+
} else if let languagePrefix = knownLanguagePrefixes.first(where: { kind.starts(with: $0) }) {
114+
let kindWithoutLanguage = String(kind.dropFirst(languagePrefix.count))
115+
return PathComponent(full: full, name: name, kind: kindWithoutLanguage, hash: hash)
115116
}
116117
}
117118
return PathComponent(full: full, name: name, kind: nil, hash: hash)

Tests/SwiftDocCTests/Infrastructure/DocumentationContext/DocumentationContextTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1667,14 +1667,17 @@ let expected = """
16671667
try """
16681668
# ``Operators/MyNumber``
16691669
1670-
A documentation extension that curates symbosl with characters not allowed in a resolved reference URL.
1670+
A documentation extension that curates symbols with characters not allowed in a resolved reference URL.
16711671
16721672
## Topics
16731673
16741674
- ``<(_:_:)``
16751675
- ``>(_:_:)``
16761676
- ``<=(_:_:)``
16771677
- ``>=(_:_:)``
1678+
- ``-(_:_:)-22pw2``
1679+
- ``-(_:)-9xdx0``
1680+
- ``-=(_:_:)-7w3vn``
16781681
""".write(to: root.appendingPathComponent("doc-extension.md"), atomically: true, encoding: .utf8)
16791682
}
16801683

Tests/SwiftDocCTests/Infrastructure/PathHierarchyTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,14 @@ class PathHierarchyTests: XCTestCase {
13321332
XCTAssertEqual(try tree.findSymbol(path: "<=(_:_:)", parent: myNumberID).identifier.precise, "s:SLsE2leoiySbx_xtFZ::SYNTHESIZED::s:9Operators8MyNumberV")
13331333
XCTAssertEqual(try tree.findSymbol(path: ">=(_:_:)", parent: myNumberID).identifier.precise, "s:SLsE2geoiySbx_xtFZ::SYNTHESIZED::s:9Operators8MyNumberV")
13341334

1335+
XCTAssertEqual(try tree.findSymbol(path: "-(_:_:)-22pw2", parent: myNumberID).identifier.precise, "s:9Operators8MyNumberV1soiyA2C_ACtFZ")
1336+
XCTAssertEqual(try tree.findSymbol(path: "-(_:)-9xdx0", parent: myNumberID).identifier.precise, "s:s13SignedNumericPsE1sopyxxFZ::SYNTHESIZED::s:9Operators8MyNumberV")
1337+
XCTAssertEqual(try tree.findSymbol(path: "-=(_:_:)-7w3vn", parent: myNumberID).identifier.precise, "s:s18AdditiveArithmeticPsE2seoiyyxz_xtFZ::SYNTHESIZED::s:9Operators8MyNumberV")
1338+
1339+
XCTAssertEqual(try tree.findSymbol(path: "-(_:_:)-func.op", parent: myNumberID).identifier.precise, "s:9Operators8MyNumberV1soiyA2C_ACtFZ")
1340+
XCTAssertEqual(try tree.findSymbol(path: "-(_:)-func.op", parent: myNumberID).identifier.precise, "s:s13SignedNumericPsE1sopyxxFZ::SYNTHESIZED::s:9Operators8MyNumberV")
1341+
XCTAssertEqual(try tree.findSymbol(path: "-=(_:_:)-func.op", parent: myNumberID).identifier.precise, "s:s18AdditiveArithmeticPsE2seoiyyxz_xtFZ::SYNTHESIZED::s:9Operators8MyNumberV")
1342+
13351343
let paths = tree.caseInsensitiveDisambiguatedPaths()
13361344

13371345
// Unmodified operator name in URL
@@ -1622,6 +1630,8 @@ class PathHierarchyTests: XCTestCase {
16221630
assertParsedPathComponents("path-swift.type.property-hash", [("path", "type.property", "hash")])
16231631
assertParsedPathComponents("path-type.property", [("path", "type.property", nil)])
16241632
assertParsedPathComponents("path-swift.type.property", [("path", "type.property", nil)])
1633+
1634+
assertParsedPathComponents("-(_:_:)-hash", [("-(_:_:)", nil, "hash")])
16251635
}
16261636

16271637
// MARK: Test helpers

0 commit comments

Comments
 (0)