Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix unused opens false positive for record fields
  • Loading branch information
auduchinok committed May 24, 2019
commit d48da25976ae5406eca754cb74ade7eb8f921759
9 changes: 9 additions & 0 deletions src/fsharp/service/ServiceAnalysis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,26 @@ module UnusedOpens =
| :? FSharpMemberOrFunctionOrValue as fv when fv.IsExtensionMember ->
// Extension members should be taken into account even though they have a prefix (as they do most of the time)
true

| :? FSharpMemberOrFunctionOrValue as fv when not fv.IsModuleValueOrMember ->
// Local values can be ignored
false

| :? FSharpMemberOrFunctionOrValue when su.IsFromDefinition ->
// Value definitions should be ignored
false

| :? FSharpGenericParameter ->
// Generic parameters can be ignored, they never come into scope via 'open'
false

| :? FSharpUnionCase when su.IsFromDefinition ->
false

| :? FSharpField ->
// Record fields are used in name resolution
true

| _ ->
// For the rest of symbols we pick only those which are the first part of a long ident, because it's they which are
// contained in opened namespaces / modules. For example, we pick `IO` from long ident `IO.File.OpenWrite` because
Expand Down
8 changes: 8 additions & 0 deletions tests/service/ProjectAnalysisTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5523,6 +5523,14 @@ type UseTheThings(i:int) =
member x.UseSomeUsedModuleContainingActivePattern(ActivePattern g) = g
member x.UseSomeUsedModuleContainingExtensionMember() = (3).Q
member x.UseSomeUsedModuleContainingUnion() = A

module M1 =
type R = { Field: int }

module M2 =
open M1

let foo x = x.Field
"""
let fileSource1 = FSharp.Compiler.Text.SourceText.ofString fileSource1Text
File.WriteAllText(fileName1, fileSource1Text)
Expand Down