Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb561754

Browse files
Vasily KirichenkoVasily Kirichenko
Vasily Kirichenko
authored and
Vasily Kirichenko
committed
fixed: opening nested auto open module makes outer module as unused
1 parente55de7e commitb561754

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

‎src/fsharp/vs/ServiceAnalysis.fs‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ open Microsoft.FSharp.Compiler.Range
99
moduleUnusedOpens=
1010
openMicrosoft.FSharp.Compiler.PrettyNaming
1111

12+
typeModule=
13+
{ Entity:FSharpEntity
14+
IsNestedAutoOpen:bool}
15+
1216
/// Represents single open statement.
1317
typeOpenStatement=
1418
{/// All modules which this open declaration effectively opens, including all auto open ones, recursively.
15-
Modules:FSharpEntity list
19+
Modules:Module list
1620
/// Range of open statement itself.
1721
Range:range
1822
/// Scope on which this open declaration is applied.
@@ -21,7 +25,7 @@ module UnusedOpens =
2125
IsGlobal:bool}
2226

2327
memberthis.AllChildSymbols=
24-
seq{for modulin this.Modulesdo
28+
seq{for modulin this.Modules|> List.map(fun x-> x.Entity)do
2529
for entin modul.NestedEntitiesdo
2630
yield ent:> FSharpSymbol
2731

@@ -40,19 +44,19 @@ module UnusedOpens =
4044
yieldupcast apCase
4145
}|> Seq.cache
4246

43-
let recgetModuleAndItsAutoOpens(modul:FSharpEntity)=
44-
[yield modul
47+
let recgetModuleAndItsAutoOpens(isNestedAutoOpen:bool)(modul:FSharpEntity)=
48+
[yield{ Entity=modul; IsNestedAutoOpen= isNestedAutoOpen}
4549
for entin modul.NestedEntitiesdo
4650
if ent.IsFSharpModule&& Symbol.hasAttribute<AutoOpenAttribute> ent.Attributesthen
47-
yield! getModuleAndItsAutoOpens ent]
51+
yield! getModuleAndItsAutoOpenstrueent]
4852

4953
letgetOpenStatements(openDeclarations:FSharpOpenDeclaration list):OpenStatement list=
5054
openDeclarations
5155
|> List.filter(fun x->not x.IsOwnNamespace)
5256
|> List.choose(fun openDecl->
5357
match openDecl.LongId, openDecl.Rangewith
5458
| firstId::_, Some range->
55-
Some{ Modules= openDecl.Modules|> List.collect getModuleAndItsAutoOpens
59+
Some{ Modules= openDecl.Modules|> List.collect(getModuleAndItsAutoOpensfalse)
5660
Range= range
5761
AppliedScope= openDecl.AppliedScope
5862
IsGlobal= firstId.idText= MangledGlobalName}
@@ -97,7 +101,12 @@ module UnusedOpens =
97101
// if such open statement has already been marked as used in this or outer module, we skip it
98102
// (that is, do not mark as used so far)
99103
rangeContainsRange seenNs.AppliedScope openStatement.AppliedScope&&
100-
openStatement.Modules|> List.exists(fun x-> seenNs.Modules|> List.exists(fun s-> s.IsEffectivelySameAs x)))
104+
openStatement.Modules
105+
|> List.exists(fun x->
106+
// do not check if any of auto open nested modules has already been seen,
107+
// current open statement should be seen itself or as an auto open module of its outer module.
108+
not x.IsNestedAutoOpen&&
109+
seenNs.Modules|> List.exists(fun s-> s.Entity.IsEffectivelySameAs x.Entity)))
101110
not alreadySeen
102111

103112
match openStatementswith

‎vsintegration/tests/unittests/UnusedOpensTests.fs‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ module Top =
166166
=>[]
167167

168168
[<Test>]
169-
let``last of several equivalentopendeclarations is market as used,the rest of them are marked as unused``()=
169+
let``opening autoopenmodule after it's parent module was opened should be marked as unused``()=
170170
"""
171171
module NormalModule =
172172
[<AutoOpen>]
@@ -178,11 +178,11 @@ module NormalModule =
178178
module AutoOpenModule3 =
179179
type Class() = class end
180180
181-
open NormalModule.AutoOpenModule1.NestedNormalModule.AutoOpenModule2
182181
open NormalModule.AutoOpenModule1.NestedNormalModule
182+
open NormalModule.AutoOpenModule1.NestedNormalModule.AutoOpenModule2
183183
let _ = Class()
184184
"""
185-
=>[13,(5,52)]
185+
=>[13,(5,68)]
186186

187187
[<Test>]
188188
let``open declaration is not marked as unused if there is a shortened attribute symbol from it``()=
@@ -649,3 +649,18 @@ namespace Library2
649649
type T() = class end
650650
"""
651651
=>[]
652+
653+
[<Test>]
654+
let``auto open module opened before enclosing one is handled correctly``()=
655+
"""
656+
module M =
657+
let x = 1
658+
[<AutoOpen>]
659+
module N =
660+
let y = 2
661+
open M.N
662+
open M
663+
let _ = x
664+
let _ = y
665+
"""
666+
=>[]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp