@@ -57,6 +57,13 @@ module UnusedOpens =
57
57
for field in entity.FSharpFields do
58
58
if field.IsStatic && field.IsLiteral then
59
59
field
60
+
61
+ if
62
+ entity.IsFSharpUnion
63
+ && not ( entity.HasAttribute< RequireQualifiedAccessAttribute>())
64
+ then
65
+ for unionCase in entity.UnionCases do
66
+ unionCase
60
67
|]
61
68
62
69
HashSet<_>( symbols, symbolHash)
@@ -75,7 +82,7 @@ module UnusedOpens =
75
82
[|
76
83
yield OpenedModule( modul, isNestedAutoOpen)
77
84
for ent in modul.NestedEntities do
78
- if ent.IsFSharpModule && ent. HasAttribute< AutoOpenAttribute>() then
85
+ if ent.HasAttribute< AutoOpenAttribute>() then
79
86
yield ! getModuleAndItsAutoOpens true ent
80
87
|]
81
88
@@ -192,7 +199,7 @@ module UnusedOpens =
192
199
not (
193
200
usedModules.BagExistsValueForKey(
194
201
openedEntity.Entity,
195
- fun scope -> rangeContainsRange scope openStatement.AppliedScope
202
+ fun scope -> rangeContainsRange openStatement.AppliedScope scope
196
203
)
197
204
))
198
205
@@ -271,7 +278,7 @@ module UnusedOpens =
271
278
272
279
/// Filter out the open statements whose contents are referred to somewhere in the symbol uses.
273
280
/// Async to allow cancellation.
274
- let filterOpenStatements ( symbolUses1 : FSharpSymbolUse [], symbolUses2 : FSharpSymbolUse []) openStatements =
281
+ let filterOpenStatements ( symbolUses1 : FSharpSymbolUse [], symbolUses2 : FSharpSymbolUse []) ( openStatements : OpenStatement []) =
275
282
async {
276
283
// the key is a namespace or module, the value is a list of FSharpSymbolUse range of symbols defined in the
277
284
// namespace or module. So, it's just symbol uses ranges grouped by namespace or module where they are _defined_.
@@ -284,18 +291,25 @@ module UnusedOpens =
284
291
match f.DeclaringEntity with
285
292
| Some entity when entity.IsNamespace || entity.IsFSharpModule ->
286
293
symbolUsesRangesByDeclaringEntity.BagAdd( entity, symbolUse.Range)
294
+
295
+ if f.ApparentEnclosingEntity <> entity then
296
+ symbolUsesRangesByDeclaringEntity.BagAdd( f.ApparentEnclosingEntity, symbolUse.Range)
287
297
| _ -> ()
288
298
| _ -> ()
289
299
300
+ // Check the open statements in reverse order to account for shadowing.
301
+ let reversedOpenStatements = openStatements |> List.ofArray |> List.rev
302
+
290
303
let! results =
291
304
filterOpenStatementsIncremental
292
305
symbolUses2
293
306
symbolUsesRangesByDeclaringEntity
294
- ( List.ofArray openStatements )
307
+ reversedOpenStatements
295
308
( Dictionary( entityHash))
296
309
[]
297
310
298
- return results |> List.map ( fun os -> os.Range)
311
+ // Re-reverse the results.
312
+ return results |> List.map _. Range |> List.rev
299
313
}
300
314
301
315
/// Get the open statements whose contents are not referred to anywhere in the symbol uses.
0 commit comments