Skip to content

Commit 1e4d162

Browse files
committed
add test for IsArrayType and ArrayRank
1 parent 5a38af3 commit 1e4d162

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/fsharp/vs/Symbols.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ and [<Class>] FSharpEntity =
167167
/// Indicates if the entity is an array type
168168
member IsArrayType : bool
169169

170-
/// Gets the rank of an array type
170+
/// Get the rank of an array type
171171
member ArrayRank : int
172172

173173
/// Indicates if the entity is a 'fake' symbol related to a static instantiation of a type provider

tests/service/ProjectAnalysisTests.fs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,6 +3024,8 @@ type AnotherMutableList() =
30243024
let f1 (x: System.Collections.Generic.IList<'T>) = () // grab the IList symbol and look into it
30253025
let f2 (x: AnotherMutableList) = () // grab the AnotherMutableList symbol and look into it
30263026
let f3 (x: System.Collections.ObjectModel.ObservableCollection<'T>) = () // grab the ObservableCollection symbol and look into it
3027+
let f4 (x: int[]) = () // test a one-dimensional array
3028+
let f5 (x: int[,,]) = () // test a multi-dimensional array
30273029
"""
30283030
File.WriteAllText(fileName1, fileSource1)
30293031
let cleanFileName a = if a = fileName1 then "file1" else "??"
@@ -3046,21 +3048,33 @@ let ``Test Project22 IList contents`` () =
30463048

30473049
let wholeProjectResults = checker.ParseAndCheckProject(Project22.options) |> Async.RunSynchronously
30483050

3049-
let ilistTypeUse =
3051+
let allUsesOfAllSymbols =
30503052
wholeProjectResults.GetAllUsesOfAllSymbols()
30513053
|> Async.RunSynchronously
3054+
3055+
let ilistTypeUse =
3056+
allUsesOfAllSymbols
30523057
|> Array.find (fun su -> su.Symbol.DisplayName = "IList")
30533058

30543059
let ocTypeUse =
3055-
wholeProjectResults.GetAllUsesOfAllSymbols()
3056-
|> Async.RunSynchronously
3060+
allUsesOfAllSymbols
30573061
|> Array.find (fun su -> su.Symbol.DisplayName = "ObservableCollection")
30583062

30593063
let alistTypeUse =
3060-
wholeProjectResults.GetAllUsesOfAllSymbols()
3061-
|> Async.RunSynchronously
3064+
allUsesOfAllSymbols
30623065
|> Array.find (fun su -> su.Symbol.DisplayName = "AnotherMutableList")
30633066

3067+
let allTypes =
3068+
allUsesOfAllSymbols
3069+
|> Array.choose (fun su -> match su.Symbol with :? FSharpMemberOrFunctionOrValue as s -> Some s.FullType | _ -> None )
3070+
3071+
let arrayTypes =
3072+
allTypes
3073+
|> Array.choose (fun t ->
3074+
if t.HasTypeDefinition then
3075+
let td = t.TypeDefinition
3076+
if td.IsArrayType then Some (td.DisplayName, td.ArrayRank) else None
3077+
else None )
30643078

30653079
let ilistTypeDefn = ilistTypeUse.Symbol :?> FSharpEntity
30663080
let ocTypeDefn = ocTypeUse.Symbol :?> FSharpEntity
@@ -3109,6 +3123,8 @@ let ``Test Project22 IList contents`` () =
31093123
(set [("IList", ["interface"]); ("ICollection", ["interface"]);
31103124
("IEnumerable", ["interface"]); ("IEnumerable", ["interface"])])
31113125

3126+
arrayTypes |> shouldEqual [|("[]", 1); ("[,,]", 3)|]
3127+
31123128
[<Test>]
31133129
let ``Test Project22 IList properties`` () =
31143130

0 commit comments

Comments
 (0)