Skip to content

Commit

Permalink
Fix unused open type declaration detection
Browse files Browse the repository at this point in the history
  • Loading branch information
asik committed Nov 20, 2020
1 parent 7036c05 commit ff6f797
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/fsharp/service/ServiceAnalysis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ module UnusedOpens =
yield! getModuleAndItsAutoOpens true ent |]
{ OpenedModules = getModuleAndItsAutoOpens false modul }

/// Represents single open statement.
/// Represents a single open statement
type OpenStatement =
{ /// All namespaces and modules which this open declaration effectively opens, including the AutoOpen ones
{ /// All namespaces, modules and types which this open declaration effectively opens, including the AutoOpen ones
OpenedGroups: OpenedModuleGroup list

/// The range of open statement itself
Expand All @@ -90,7 +90,8 @@ module UnusedOpens =
if firstId.idText = MangledGlobalName then
None
else
Some { OpenedGroups = openDecl.Modules |> List.map OpenedModuleGroup.Create
let openedModulesAndTypes = List.concat [openDecl.Modules; openDecl.Types |> List.map(fun ty -> ty.TypeDefinition)]
Some { OpenedGroups = openedModulesAndTypes |> List.map OpenedModuleGroup.Create
Range = range
AppliedScope = openDecl.AppliedScope }
| _ -> None)
Expand Down
11 changes: 10 additions & 1 deletion vsintegration/tests/UnitTests/UnusedOpensTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -808,4 +808,13 @@ open Nested
let _ = f 1
"""
=> []
=> []

[<Test>]
let ``open type``() =
"""
open type System.Console
WriteLine("Hello World")
"""
=> [2, (10, 24)]

0 comments on commit ff6f797

Please sign in to comment.