Skip to content

Commit 54fb3da

Browse files
authored
Checker: don't capture environment for checked modules (#18519)
1 parent 9995898 commit 54fb3da

File tree

5 files changed

+74
-11
lines changed

5 files changed

+74
-11
lines changed

docs/release-notes/.FSharp.Compiler.Service/9.0.300.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* Fix missing `null` highlighting in tooltips ([PR #18457](https://github.com/dotnet/fsharp/pull/18457))
2828
* Allow `_` in `use!` bindings values (lift FS1228 restriction) ([PR #18487](https://github.com/dotnet/fsharp/pull/18487))
2929
* Make `[<CallerMemberName; Struct>]` combination work([PR #18444](https://github.com/dotnet/fsharp/pull/18444/))
30+
* Fix code completion considers types from own namespace non-imported ([PR #18518](https://github.com/dotnet/fsharp/issues/18518))
3031

3132
### Added
3233
* Added missing type constraints in FCS. ([PR #18241](https://github.com/dotnet/fsharp/pull/18241))

src/Compiler/Checking/CheckDeclarations.fs

+5-6
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ let AddNonLocalCcu g amap scopem env assemblyName (ccu: CcuThunk, internalsVisib
341341
env
342342

343343
/// Adjust the TcEnv to account for a fully processed "namespace" declaration in this file
344-
let AddLocalRootModuleOrNamespace tcSink g amap scopem env (moduleTy: ModuleOrNamespaceType) =
344+
let AddLocalRootModuleOrNamespace g amap scopem env (moduleTy: ModuleOrNamespaceType) =
345345
// Compute the top-rooted module or namespace references
346346
let modrefs = moduleTy.ModuleAndNamespaceDefinitions |> List.map mkLocalModuleRef
347347
// Compute the top-rooted type definitions
@@ -350,7 +350,6 @@ let AddLocalRootModuleOrNamespace tcSink g amap scopem env (moduleTy: ModuleOrNa
350350
let env = { env with
351351
eNameResEnv = if isNil tcrefs then env.eNameResEnv else AddTyconRefsToNameEnv BulkAdd.No false g amap env.eAccessRights scopem true env.eNameResEnv tcrefs
352352
eUngeneralizableItems = addFreeItemOfModuleTy moduleTy env.eUngeneralizableItems }
353-
CallEnvSink tcSink (scopem, env.NameEnv, env.eAccessRights)
354353
env
355354

356355
/// Inside "namespace X.Y.Z" there is an implicit open of "X.Y.Z"
@@ -4978,7 +4977,7 @@ let rec TcSignatureElementNonMutRec (cenv: cenv) parent typeNames endm (env: TcE
49784977
CallNameResolutionSink cenv.tcSink (moduleEntity.Range, env.NameEnv, item, emptyTyparInst, ItemOccurrence.Binding, env.AccessRights))
49794978

49804979
// For 'namespace rec' and 'module rec' we add the thing being defined
4981-
let envNS = if isRec then AddLocalRootModuleOrNamespace cenv.tcSink g cenv.amap m envNS modTyRoot else envNS
4980+
let envNS = if isRec then AddLocalRootModuleOrNamespace g cenv.amap m envNS modTyRoot else envNS
49824981
let nsInfo = Some (modulNSOpt, envNS.eModuleOrNamespaceTypeAccumulator)
49834982
let mutRecNSInfo = if isRec then nsInfo else None
49844983

@@ -4990,7 +4989,7 @@ let rec TcSignatureElementNonMutRec (cenv: cenv) parent typeNames endm (env: TcE
49904989
if isNil enclosingNamespacePath then
49914990
envAtEnd
49924991
else
4993-
let env = AddLocalRootModuleOrNamespace cenv.tcSink g cenv.amap m env modTyRoot
4992+
let env = AddLocalRootModuleOrNamespace g cenv.amap m env modTyRoot
49944993

49954994
// If the namespace is an interactive fragment e.g. FSI_0002, then open FSI_0002 in the subsequent environment.
49964995
let env, _openDecls =
@@ -5440,7 +5439,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
54405439
CallNameResolutionSink cenv.tcSink (moduleEntity.Range, env.NameEnv, item, emptyTyparInst, ItemOccurrence.Binding, env.AccessRights))
54415440

54425441
// For 'namespace rec' and 'module rec' we add the thing being defined
5443-
let envNS = if isRec then AddLocalRootModuleOrNamespace cenv.tcSink g cenv.amap m envNS modTyRoot else envNS
5442+
let envNS = if isRec then AddLocalRootModuleOrNamespace g cenv.amap m envNS modTyRoot else envNS
54445443
let nsInfo = Some (modulNSOpt, envNS.eModuleOrNamespaceTypeAccumulator)
54455444
let mutRecNSInfo = if isRec then nsInfo else None
54465445

@@ -5453,7 +5452,7 @@ let rec TcModuleOrNamespaceElementNonMutRec (cenv: cenv) parent typeNames scopem
54535452
if isNil enclosingNamespacePath then
54545453
envAtEnd, []
54555454
else
5456-
let env = AddLocalRootModuleOrNamespace cenv.tcSink g cenv.amap m env modTyRoot
5455+
let env = AddLocalRootModuleOrNamespace g cenv.amap m env modTyRoot
54575456

54585457
// If the namespace is an interactive fragment e.g. FSI_0002, then open FSI_0002 in the subsequent environment
54595458
let env, openDecls =

src/Compiler/Checking/CheckDeclarations.fsi

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ open FSharp.Compiler.TcGlobals
1313
open FSharp.Compiler.Text
1414
open FSharp.Compiler.TypedTree
1515

16-
val AddLocalRootModuleOrNamespace:
17-
TcResultsSink -> TcGlobals -> ImportMap -> range -> TcEnv -> ModuleOrNamespaceType -> TcEnv
16+
val AddLocalRootModuleOrNamespace: TcGlobals -> ImportMap -> range -> TcEnv -> ModuleOrNamespaceType -> TcEnv
1817

1918
val CreateInitialTcEnv:
2019
TcGlobals * ImportMap * range * assemblyName: string * (CcuThunk * string list * string list) list ->

src/Compiler/Driver/ParseAndCheckInputs.fs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1198,14 +1198,14 @@ let AddCheckResultsToTcState
11981198

11991199
// Add the implementation as to the implementation env
12001200
let tcImplEnv =
1201-
AddLocalRootModuleOrNamespace TcResultsSink.NoSink tcGlobals amap m tcImplEnv implFileSigType
1201+
AddLocalRootModuleOrNamespace tcGlobals amap m tcImplEnv implFileSigType
12021202

12031203
// Add the implementation as to the signature env (unless it had an explicit signature)
12041204
let tcSigEnv =
12051205
if hadSig then
12061206
tcState.tcsTcSigEnv
12071207
else
1208-
AddLocalRootModuleOrNamespace TcResultsSink.NoSink tcGlobals amap m tcState.tcsTcSigEnv implFileSigType
1208+
AddLocalRootModuleOrNamespace tcGlobals amap m tcState.tcsTcSigEnv implFileSigType
12091209

12101210
// Open the prefixPath for fsi.exe (tcImplEnv)
12111211
let tcImplEnv, openDecls =
@@ -1563,7 +1563,7 @@ let CheckOneInputWithCallback
15631563
let rootSigs = Zmap.add qualNameOfFile sigFileType tcState.tcsRootSigs
15641564

15651565
let tcSigEnv =
1566-
AddLocalRootModuleOrNamespace TcResultsSink.NoSink tcGlobals amap m tcState.tcsTcSigEnv sigFileType
1566+
AddLocalRootModuleOrNamespace tcGlobals amap m tcState.tcsTcSigEnv sigFileType
15671567

15681568
// Add the signature to the signature env (unless it had an explicit signature)
15691569
let ccuSigForFile = CombineCcuContentFragments [ sigFileType; tcState.tcsCcuSig ]

tests/FSharp.Compiler.Service.Tests/CompletionTests.fs

+64
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,67 @@ let f (s: string) =
134134
()
135135
"""
136136
assertHasItemWithNames ["Length"] info
137+
138+
139+
[<Fact>]
140+
let ``Import - Ns 01`` () =
141+
let info =
142+
getCompletionInfo "let _: R " (14, 12) """
143+
namespace Ns
144+
145+
type Rec1 = { F: int }
146+
147+
148+
namespace Ns
149+
150+
type Rec2 = { F: int }
151+
152+
module M =
153+
154+
type Rec3 = { F: int }
155+
156+
let _: R = ()
157+
"""
158+
assertHasItemWithNames ["Rec1"; "Rec2"; "Rec3"] info
159+
160+
[<Fact>]
161+
let ``Import - Ns 02 - Rec`` () =
162+
let info =
163+
getCompletionInfo "let _: R " (14, 12) """
164+
namespace Ns
165+
166+
type Rec1 = { F: int }
167+
168+
169+
namespace rec Ns
170+
171+
type Rec2 = { F: int }
172+
173+
module M =
174+
175+
type Rec3 = { F: int }
176+
177+
let _: R = ()
178+
"""
179+
assertHasItemWithNames ["Rec1"; "Rec2"; "Rec3"] info
180+
181+
[<Fact>]
182+
let ``Import - Ns 03 - Rec`` () =
183+
let info =
184+
getCompletionInfo "let _: R " (14, 12) """
185+
namespace Ns
186+
187+
type Rec1 = { F: int }
188+
189+
190+
namespace rec Ns
191+
192+
type Rec2 = { F: int }
193+
194+
module rec M =
195+
196+
type Rec3 = { F: int }
197+
198+
let _: R = ()
199+
"""
200+
assertHasItemWithNames ["Rec1"; "Rec2"; "Rec3"] info

0 commit comments

Comments
 (0)