@@ -1408,6 +1408,19 @@ class PathHierarchyTests: XCTestCase {
1408
1408
. init( kind: . text, spelling: " > " , preciseIdentifier: nil ) ,
1409
1409
] ) )
1410
1410
1411
+ // Any
1412
+ XCTAssertEqual ( " Any " , functionSignatureParameterTypeName ( [
1413
+ . init( kind: . keyword, spelling: " Any " , preciseIdentifier: nil ) ,
1414
+ ] ) )
1415
+
1416
+ // Array<Any>
1417
+ XCTAssertEqual ( " [Any] " , functionSignatureParameterTypeName ( [
1418
+ . init( kind: . typeIdentifier, spelling: " Array " , preciseIdentifier: " s:Sa " ) ,
1419
+ . init( kind: . text, spelling: " < " , preciseIdentifier: nil ) ,
1420
+ . init( kind: . keyword, spelling: " Any " , preciseIdentifier: nil ) ,
1421
+ . init( kind: . text, spelling: " > " , preciseIdentifier: nil ) ,
1422
+ ] ) )
1423
+
1411
1424
// some Sequence<Int>
1412
1425
XCTAssertEqual ( " Sequence<Int> " , functionSignatureParameterTypeName ( [
1413
1426
. init( kind: . keyword, spelling: " some " , preciseIdentifier: nil ) ,
@@ -1773,7 +1786,7 @@ class PathHierarchyTests: XCTestCase {
1773
1786
. init( name: " someName " , externalName: nil , declarationFragments: [
1774
1787
. init( kind: . identifier, spelling: " someName " , preciseIdentifier: nil ) ,
1775
1788
. init( kind: . text, spelling: " : (( " , preciseIdentifier: nil ) ,
1776
- . init( kind: . typeIdentifier , spelling: " Int " , preciseIdentifier: " s:Si " ) ,
1789
+ . init( kind: . keyword , spelling: " Any " , preciseIdentifier: nil ) ,
1777
1790
. init( kind: . text, spelling: " , " , preciseIdentifier: nil ) ,
1778
1791
. init( kind: . typeIdentifier, spelling: " String " , preciseIdentifier: " s:SS " ) ,
1779
1792
. init( kind: . text, spelling: " ), " , preciseIdentifier: nil ) ,
@@ -1789,10 +1802,10 @@ class PathHierarchyTests: XCTestCase {
1789
1802
. init( kind: . text, spelling: " ?) " , preciseIdentifier: nil ) ,
1790
1803
] )
1791
1804
)
1792
- XCTAssertEqual ( tupleArgument? . parameterTypeNames, [ " ((Int ,String),Date) " ] )
1805
+ XCTAssertEqual ( tupleArgument? . parameterTypeNames, [ " ((Any ,String),Date) " ] )
1793
1806
XCTAssertEqual ( tupleArgument? . returnTypeNames, [ " [Int] " , " String? " ] )
1794
1807
1795
- // func doSomething() -> ((Double, Double) -> Double, [Int: (Int, Int)], (Bool, Bool ), String?)
1808
+ // func doSomething() -> ((Double, Double) -> Double, [Int: (Int, Int)], (Bool, Any ), String?)
1796
1809
let bigTupleReturnType = functionSignatureTypeNames ( . init(
1797
1810
parameters: [ ] ,
1798
1811
returns: [
@@ -1811,7 +1824,7 @@ class PathHierarchyTests: XCTestCase {
1811
1824
. init( kind: . text, spelling: " )], ( " , preciseIdentifier: nil ) ,
1812
1825
. init( kind: . typeIdentifier, spelling: " Bool " , preciseIdentifier: " s:Si " ) ,
1813
1826
. init( kind: . text, spelling: " , " , preciseIdentifier: nil ) ,
1814
- . init( kind: . typeIdentifier , spelling: " Bool " , preciseIdentifier: " s:Si " ) ,
1827
+ . init( kind: . keyword , spelling: " Any " , preciseIdentifier: nil ) ,
1815
1828
. init( kind: . text, spelling: " ), " , preciseIdentifier: nil ) ,
1816
1829
. init( kind: . typeIdentifier, spelling: " Optional " , preciseIdentifier: " s:Sq " ) ,
1817
1830
. init( kind: . text, spelling: " < " , preciseIdentifier: nil ) ,
@@ -1820,7 +1833,7 @@ class PathHierarchyTests: XCTestCase {
1820
1833
] )
1821
1834
)
1822
1835
XCTAssertEqual ( bigTupleReturnType? . parameterTypeNames, [ ] )
1823
- XCTAssertEqual ( bigTupleReturnType? . returnTypeNames, [ " (Double,Double)->Double " , " [Int:(Int,Int)] " , " (Bool,Bool ) " , " String? " ] )
1836
+ XCTAssertEqual ( bigTupleReturnType? . returnTypeNames, [ " (Double,Double)->Double " , " [Int:(Int,Int)] " , " (Bool,Any ) " , " String? " ] )
1824
1837
1825
1838
// func doSomething(with someName: [Int?: String??])
1826
1839
let dictionaryWithOptionalsArgument = functionSignatureTypeNames ( . init(
@@ -1918,6 +1931,112 @@ class PathHierarchyTests: XCTestCase {
1918
1931
}
1919
1932
}
1920
1933
1934
+ func testParameterDisambiguationWithAnyType( ) throws {
1935
+ // Create two overloads with different parameter types
1936
+ let parameterTypes : [ SymbolGraph . Symbol . DeclarationFragments . Fragment ] = [
1937
+ // Any (swift)
1938
+ . init( kind: . keyword, spelling: " Any " , preciseIdentifier: nil ) ,
1939
+ // AnyObject (swift)
1940
+ . init( kind: . typeIdentifier, spelling: " AnyObject " , preciseIdentifier: " s:s9AnyObjecta " ) ,
1941
+ ]
1942
+
1943
+ let catalog = Folder ( name: " CatalogName.docc " , content: [
1944
+ JSONFile ( name: " ModuleName.symbols.json " , content: makeSymbolGraph ( moduleName: " ModuleName " , symbols: parameterTypes. map { parameterTypeFragment in
1945
+ makeSymbol ( id: " some-function-id- \( parameterTypeFragment. spelling) " , kind: . func, pathComponents: [ " doSomething(with:) " ] , signature: . init(
1946
+ parameters: [
1947
+ . init( name: " something " , externalName: " with " , declarationFragments: [
1948
+ . init( kind: . identifier, spelling: " something " , preciseIdentifier: nil ) ,
1949
+ . init( kind: . text, spelling: " : " , preciseIdentifier: nil ) ,
1950
+ parameterTypeFragment
1951
+ ] , children: [ ] )
1952
+ ] ,
1953
+ returns: [
1954
+ . init( kind: . text, spelling: " () " , preciseIdentifier: nil ) // 'Void' in text representation
1955
+ ]
1956
+ ) )
1957
+ } ) ) ,
1958
+ ] )
1959
+ let ( _, context) = try loadBundle ( catalog: catalog)
1960
+ let tree = context. linkResolver. localResolver. pathHierarchy
1961
+
1962
+ XCTAssert ( context. problems. isEmpty, " Unexpected problems \( context. problems. map ( \. diagnostic. summary) ) " )
1963
+
1964
+ let paths = tree. caseInsensitiveDisambiguatedPaths ( )
1965
+
1966
+ XCTAssertEqual ( paths [ " some-function-id-Any " ] , " /ModuleName/doSomething(with:)-(Any) " )
1967
+ XCTAssertEqual ( paths [ " some-function-id-AnyObject " ] , " /ModuleName/doSomething(with:)-(AnyObject) " )
1968
+
1969
+ try assertPathCollision ( " doSomething(with:) " , in: tree, collisions: [
1970
+ ( " some-function-id-Any " , " -(Any) " ) ,
1971
+ ( " some-function-id-AnyObject " , " -(AnyObject) " ) ,
1972
+ ] )
1973
+
1974
+ try assertPathRaisesErrorMessage ( " doSomething(with:) " , in: tree, context: context, expectedErrorMessage: " 'doSomething(with:)' is ambiguous at '/ModuleName' " ) { error in
1975
+ XCTAssertEqual ( error. solutions. count, 2 )
1976
+
1977
+ // These test symbols don't have full declarations. A real solution would display enough information to distinguish these.
1978
+ XCTAssertEqual ( error. solutions. dropFirst ( 0 ) . first, . init( summary: " Insert '-(Any)' for \n 'doSomething(with:)' " , replacements: [ ( " -(Any) " , 18 , 18 ) ] ) )
1979
+ XCTAssertEqual ( error. solutions. dropFirst ( 1 ) . first, . init( summary: " Insert '-(AnyObject)' for \n 'doSomething(with:)' " /* the test symbols don't have full declarations */, replacements: [ ( " -(AnyObject) " , 18 , 18 ) ] ) )
1980
+ }
1981
+
1982
+ try assertFindsPath ( " doSomething(with:)-(Any) " , in: tree, asSymbolID: " some-function-id-Any " )
1983
+ try assertFindsPath ( " doSomething(with:)-(Any)->() " , in: tree, asSymbolID: " some-function-id-Any " )
1984
+ try assertFindsPath ( " doSomething(with:)-5gdco " , in: tree, asSymbolID: " some-function-id-Any " )
1985
+
1986
+ try assertFindsPath ( " doSomething(with:)-(AnyObject) " , in: tree, asSymbolID: " some-function-id-AnyObject " )
1987
+ try assertFindsPath ( " doSomething(with:)-(AnyObject)->() " , in: tree, asSymbolID: " some-function-id-AnyObject " )
1988
+ try assertFindsPath ( " doSomething(with:)-9kd0v " , in: tree, asSymbolID: " some-function-id-AnyObject " )
1989
+ }
1990
+
1991
+ func testReturnDisambiguationWithAnyType( ) throws {
1992
+ // Create two overloads with different return types
1993
+ let returnTypes : [ SymbolGraph . Symbol . DeclarationFragments . Fragment ] = [
1994
+ // Any (swift)
1995
+ . init( kind: . keyword, spelling: " Any " , preciseIdentifier: nil ) ,
1996
+ // AnyObject (swift)
1997
+ . init( kind: . typeIdentifier, spelling: " AnyObject " , preciseIdentifier: " s:s9AnyObjecta " ) ,
1998
+ ]
1999
+
2000
+ let catalog = Folder ( name: " CatalogName.docc " , content: [
2001
+ JSONFile ( name: " ModuleName.symbols.json " , content: makeSymbolGraph ( moduleName: " ModuleName " , symbols: returnTypes. map { parameterTypeFragment in
2002
+ makeSymbol ( id: " some-function-id- \( parameterTypeFragment. spelling) " , kind: . func, pathComponents: [ " doSomething() " ] , signature: . init(
2003
+ parameters: [ ] ,
2004
+ returns: [ parameterTypeFragment]
2005
+ ) )
2006
+ } ) ) ,
2007
+ ] )
2008
+ let ( _, context) = try loadBundle ( catalog: catalog)
2009
+ let tree = context. linkResolver. localResolver. pathHierarchy
2010
+
2011
+ XCTAssert ( context. problems. isEmpty, " Unexpected problems \( context. problems. map ( \. diagnostic. summary) ) " )
2012
+
2013
+ let paths = tree. caseInsensitiveDisambiguatedPaths ( )
2014
+
2015
+ XCTAssertEqual ( paths [ " some-function-id-Any " ] , " /ModuleName/doSomething()->Any " )
2016
+ XCTAssertEqual ( paths [ " some-function-id-AnyObject " ] , " /ModuleName/doSomething()->AnyObject " )
2017
+
2018
+ try assertPathCollision ( " doSomething() " , in: tree, collisions: [
2019
+ ( " some-function-id-Any " , " ->Any " ) ,
2020
+ ( " some-function-id-AnyObject " , " ->AnyObject " ) ,
2021
+ ] )
2022
+
2023
+ try assertPathRaisesErrorMessage ( " doSomething() " , in: tree, context: context, expectedErrorMessage: " 'doSomething()' is ambiguous at '/ModuleName' " ) { error in
2024
+ XCTAssertEqual ( error. solutions. count, 2 )
2025
+
2026
+ // These test symbols don't have full declarations. A real solution would display enough information to distinguish these.
2027
+ XCTAssertEqual ( error. solutions. dropFirst ( 0 ) . first, . init( summary: " Insert '->Any' for \n 'doSomething()' " , replacements: [ ( " ->Any " , 13 , 13 ) ] ) )
2028
+ XCTAssertEqual ( error. solutions. dropFirst ( 1 ) . first, . init( summary: " Insert '->AnyObject' for \n 'doSomething()' " /* the test symbols don't have full declarations */, replacements: [ ( " ->AnyObject " , 13 , 13 ) ] ) )
2029
+ }
2030
+
2031
+ try assertFindsPath ( " doSomething()->Any " , in: tree, asSymbolID: " some-function-id-Any " )
2032
+ try assertFindsPath ( " doSomething()-()->Any " , in: tree, asSymbolID: " some-function-id-Any " )
2033
+ try assertFindsPath ( " doSomething()-5gdco " , in: tree, asSymbolID: " some-function-id-Any " )
2034
+
2035
+ try assertFindsPath ( " doSomething()->AnyObject " , in: tree, asSymbolID: " some-function-id-AnyObject " )
2036
+ try assertFindsPath ( " doSomething()-()->AnyObject " , in: tree, asSymbolID: " some-function-id-AnyObject " )
2037
+ try assertFindsPath ( " doSomething()-9kd0v " , in: tree, asSymbolID: " some-function-id-AnyObject " )
2038
+ }
2039
+
1921
2040
func testOverloadGroupSymbolsResolveLinksWithoutHash( ) throws {
1922
2041
enableFeatureFlag ( \. isExperimentalOverloadedSymbolPresentationEnabled)
1923
2042
0 commit comments