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

Commit0037eb1

Browse files
fix for identical sub module
1 parent0366ad1 commit0037eb1

File tree

4 files changed

+99
-72
lines changed

4 files changed

+99
-72
lines changed

‎src/fsharp/TypeChecker.fs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,9 @@ let OpenModulesOrNamespaces tcSink g amap scopem root env mvvs openDeclaration =
450450
match openDeclaration.Range with
451451
| None -> ()
452452
| Some range ->
453-
let item = Item.ModuleOrNamespaces mvvs
454-
CallNameResolutionSink tcSink (range, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Use, env.DisplayEnv, env.eAccessRights)
453+
for modul in mvvs do
454+
let item = Item.ModuleOrNamespaces [modul]
455+
CallNameResolutionSink tcSink (range, env.NameEnv, item, item, emptyTyparInst, ItemOccurence.Use, env.DisplayEnv, env.eAccessRights)
455456
env
456457

457458
let AddRootModuleOrNamespaceRefs g amap m env modrefs =

‎src/fsharp/vs/ServiceAnalysis.fs‎

Lines changed: 72 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,57 @@ module UnusedOpens =
1313
{ Entity:FSharpEntity
1414
IsNestedAutoOpen:bool}
1515

16+
memberthis.ChildSymbols=
17+
seq{for entin this.Entity.NestedEntitiesdo
18+
yield ent:> FSharpSymbol
19+
20+
if ent.IsFSharpRecordthen
21+
for rfin ent.FSharpFieldsdo
22+
yieldupcast rf
23+
24+
if ent.IsFSharpUnion&&not(Symbol.hasAttribute<RequireQualifiedAccessAttribute> ent.Attributes)then
25+
for unionCasein ent.UnionCasesdo
26+
yieldupcast unionCase
27+
28+
for fvin this.Entity.MembersFunctionsAndValuesdo
29+
yieldupcast fv
30+
31+
for apCasein this.Entity.ActivePatternCasesdo
32+
yieldupcast apCase
33+
}|> Seq.cache
34+
35+
typeModuleGroup=
36+
{ Modules:Module list}
37+
38+
static memberCreate(modul:FSharpEntity)=
39+
let recgetModuleAndItsAutoOpens(isNestedAutoOpen:bool)(modul:FSharpEntity)=
40+
[yield{ Entity= modul; IsNestedAutoOpen= isNestedAutoOpen}
41+
for entin modul.NestedEntitiesdo
42+
if ent.IsFSharpModule&& Symbol.hasAttribute<AutoOpenAttribute> ent.Attributesthen
43+
yield! getModuleAndItsAutoOpenstrue ent]
44+
{ Modules= getModuleAndItsAutoOpensfalse modul}
45+
1646
/// Represents single open statement.
1747
typeOpenStatement=
18-
{/// All modules which this open declaration effectively opens, includingallauto open ones, recursively.
19-
Modules:Module list
48+
{/// All modules which this open declaration effectively opens,_not_including auto open ones.
49+
Modules:ModuleGroup list
2050
/// Range of open statement itself.
2151
Range:range
2252
/// Scope on which this open declaration is applied.
23-
AppliedScope:range
24-
/// If it's prefixed with the special "global" namespace.
25-
IsGlobal:bool}
26-
27-
memberthis.AllChildSymbols=
28-
seq{for modulin this.Modules|> List.map(fun x-> x.Entity)do
29-
for entin modul.NestedEntitiesdo
30-
yield ent:> FSharpSymbol
31-
32-
if ent.IsFSharpRecordthen
33-
for rfin ent.FSharpFieldsdo
34-
yieldupcast rf
35-
36-
if ent.IsFSharpUnion&&not(Symbol.hasAttribute<RequireQualifiedAccessAttribute> ent.Attributes)then
37-
for unionCasein ent.UnionCasesdo
38-
yieldupcast unionCase
39-
40-
for fvin modul.MembersFunctionsAndValuesdo
41-
yieldupcast fv
42-
43-
for apCasein modul.ActivePatternCasesdo
44-
yieldupcast apCase
45-
}|> Seq.cache
46-
47-
let recgetModuleAndItsAutoOpens(isNestedAutoOpen:bool)(modul:FSharpEntity)=
48-
[yield{ Entity= modul; IsNestedAutoOpen= isNestedAutoOpen}
49-
for entin modul.NestedEntitiesdo
50-
if ent.IsFSharpModule&& Symbol.hasAttribute<AutoOpenAttribute> ent.Attributesthen
51-
yield! getModuleAndItsAutoOpenstrue ent]
53+
AppliedScope:range}
5254

5355
letgetOpenStatements(openDeclarations:FSharpOpenDeclaration list):OpenStatement list=
5456
openDeclarations
5557
|> List.filter(fun x->not x.IsOwnNamespace)
5658
|> List.choose(fun openDecl->
5759
match openDecl.LongId, openDecl.Rangewith
5860
| firstId::_, Some range->
59-
Some{ Modules= openDecl.Modules|> List.collect(getModuleAndItsAutoOpensfalse)
60-
Range= range
61-
AppliedScope= openDecl.AppliedScope
62-
IsGlobal= firstId.idText= MangledGlobalName}
61+
if firstId.idText= MangledGlobalNamethen
62+
None
63+
else
64+
Some{ Modules= openDecl.Modules|> List.map ModuleGroup.Create
65+
Range= range
66+
AppliedScope= openDecl.AppliedScope}
6367
|_-> None)
6468

6569
letfilterSymbolUses(getSourceLineStr:int->string)(symbolUses:FSharpSymbolUse[]):FSharpSymbolUse[]=
@@ -76,44 +80,45 @@ module UnusedOpens =
7680
// it's `open System` which really brings it into scope.
7781
partialName.QualifyingIdents=[])
7882

83+
typeUsedModule=
84+
{ Module:FSharpEntity
85+
AppliedScope:range}
86+
7987
letgetUnusedOpens(checkFileResults:FSharpCheckFileResults,getSourceLineStr:int->string):Async<rangelist>=
8088

8189
letfilterOpenStatements(openStatements:OpenStatement list)(symbolUses:FSharpSymbolUse[]):OpenStatement list=
82-
let recfilterInner acc(openStatements:OpenStatement list)(seenOpenStatements:OpenStatement list)=
83-
84-
letisUsed(openStatement:OpenStatement)=
85-
if openStatement.IsGlobalthentrue
86-
else
87-
letusedSomewhere=
88-
symbolUses
89-
|> Array.exists(fun symbolUse->
90-
letinScope= rangeContainsRange openStatement.AppliedScope symbolUse.RangeAlternate
91-
ifnot inScopethenfalse
92-
else
93-
openStatement.AllChildSymbols
94-
|> Seq.exists(fun x-> x.IsEffectivelySameAs symbolUse.Symbol))
90+
91+
let recfilterInner acc(openStatements:OpenStatement list)(usedModules:UsedModule list)=
92+
93+
letgetUsedModules(openStatement:OpenStatement)=
94+
letnotAlreadyUsedModuleGroups=
95+
openStatement.Modules
96+
|> List.filter(fun x->
97+
not(usedModules
98+
|> List.exists(fun used->
99+
rangeContainsRange used.AppliedScope openStatement.AppliedScope&&
100+
x.Modules|> List.exists(fun x->not x.IsNestedAutoOpen&& used.Module.IsEffectivelySameAs x.Entity))))
95101

96-
ifnot usedSomewherethenfalse
97-
else
98-
letalreadySeen=
99-
seenOpenStatements
100-
|> List.exists(fun seenNs->
101-
// if such open statement has already been marked as used in this or outer module, we skip it
102-
// (that is, do not mark as used so far)
103-
rangeContainsRange seenNs.AppliedScope openStatement.AppliedScope&&
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)))
110-
not alreadySeen
111-
102+
match notAlreadyUsedModuleGroupswith
103+
|[]->[]
104+
|_->
105+
letsymbolUsesInScope= symbolUses|> Array.filter(fun symbolUse-> rangeContainsRange openStatement.AppliedScope symbolUse.RangeAlternate)
106+
notAlreadyUsedModuleGroups
107+
|> List.filter(fun modulGroup->
108+
modulGroup.Modules
109+
|> List.exists(fun modul->
110+
symbolUsesInScope
111+
|> Array.exists(fun symbolUse->
112+
modul.ChildSymbols
113+
|> Seq.exists(fun x-> x.IsEffectivelySameAs symbolUse.Symbol))))
114+
|> List.collect(fun mg->
115+
mg.Modules|> List.map(fun x->{ Module= x.Entity; AppliedScope= openStatement.AppliedScope}))
116+
112117
match openStatementswith
113-
| os:: xswhennot(isUsed os)->
114-
filterInner(os:: acc) xs(os:: seenOpenStatements)
115118
| os:: xs->
116-
filterInner acc xs(os:: seenOpenStatements)
119+
match getUsedModules oswith
120+
|[]-> filterInner(os:: acc) xs usedModules
121+
| um-> filterInner acc xs(um@ usedModules)
117122
|[]-> List.rev acc
118123

119124
filterInner[] openStatements[]

‎src/fsharp/vs/service.fs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,9 +1993,9 @@ type FSharpCheckFileResults(filename: string, errors: FSharpErrorInfo[], scopeOp
19931993
(fun()->[||])
19941994
(fun scope->
19951995
[|for(item,itemOcc,denv,m)in scope.ScopeSymbolUses.GetAllUsesOfSymbols()do
1996-
if itemOcc<> ItemOccurence.RelatedTextthen
1997-
letsymbol= FSharpSymbol.Create(scope.TcGlobals, scope.ThisCcu, scope.TcImports, item)
1998-
yield FSharpSymbolUse(scope.TcGlobals, denv, symbol, itemOcc, m)|])
1996+
if itemOcc<> ItemOccurence.RelatedTextthen
1997+
letsymbol= FSharpSymbol.Create(scope.TcGlobals, scope.ThisCcu, scope.TcImports, item)
1998+
yield FSharpSymbolUse(scope.TcGlobals, denv, symbol, itemOcc, m)|])
19991999
|> async.Return
20002000

20012001
memberinfo.GetUsesOfSymbolInFile(symbol:FSharpSymbol)=

‎vsintegration/tests/unittests/UnusedOpensTests.fs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,3 +664,24 @@ let _ = x
664664
let _ = y
665665
"""
666666
=>[]
667+
668+
[<Test>]
669+
let``single relative open declaration opens two independent modules in different parent modules``()=
670+
"""
671+
module M =
672+
module Xxx =
673+
let x = 1
674+
module N =
675+
module Xxx =
676+
let y = 1
677+
open M
678+
open N
679+
open N.Xxx
680+
open Xxx
681+
682+
let _ = y
683+
let _ = x
684+
"""
685+
=>[]
686+
687+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp