Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/fsharp/symbols/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,7 @@ and FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) =
member x.IsConstructor =
match d with
| C _ -> true
| V v -> v.IsConstructor
| _ -> false

member x.Data = d
Expand Down
31 changes: 31 additions & 0 deletions tests/service/EditorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,37 @@ type Class1() =
("member .cctor", (10, 5, 10, 11))
("Test", (1, 0, 1, 0))|]

[<Test>]
let ``IsConstructor property should return true for constructors`` () =
let input =
"""
type T(x: int) =
new() = T(0)
let x: T()
"""
let file = "/home/user/Test.fsx"
let _, typeCheckResults = parseAndCheckScript(file, input)
typeCheckResults.GetAllUsesOfAllSymbolsInFile()
|> Async.RunSynchronously
|> Array.map (fun su ->
let r = su.RangeAlternate
let isConstructor =
match su.Symbol with
| :? FSharpMemberOrFunctionOrValue as f -> f.IsConstructor
| _ -> false
su.Symbol.ToString(), (r.StartLine, r.StartColumn, r.EndLine, r.EndColumn), isConstructor)
|> Array.distinct
|> shouldEqual
[|("T", (2, 5, 2, 6), false)
("int", (2, 10, 2, 13), false)
("val x", (2, 7, 2, 8), false)
("member .ctor", (2, 5, 2, 6), true)
("member .ctor", (3, 4, 3, 7), true)
("member .ctor", (3, 12, 3, 13), true)
("T", (4, 7, 4, 8), false)
("val x", (4, 4, 4, 5), false)
("Test", (1, 0, 1, 0), false)|]

//-------------------------------------------------------------------------------


Expand Down