Skip to content

Commit 3e4cd99

Browse files
committed
Fix FCS type-checking - AutoOpen modules were being handled wrong.
Add a test that was failing before the change.
1 parent 6a482d6 commit 3e4cd99

File tree

2 files changed

+44
-16
lines changed

2 files changed

+44
-16
lines changed

tests/ParallelTypeCheckingTests/Code/ASTVisit.fs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,18 +1254,20 @@ module TopModulesExtraction =
12541254
synAccessOption,
12551255
range,
12561256
synModuleOrNamespaceTrivia) ->
1257-
if mightHaveAutoOpen synAttributeLists then
1258-
// Contents of a module that's potentially AutoOpen are available from its parent without a prefix.
1259-
// Stay safe and as soon as the parent module is reachable, consider this module reachable as well
1260-
[| LongIdent.Empty |]
1261-
else
1262-
// 'module A.B' is equivalent to 'namespace A; module B', meaning that 'A' is opened implicitly
12631257
if
1264-
synModuleOrNamespaceKind.IsModule && longId.Length > 1
1258+
mightHaveAutoOpen synAttributeLists && synModuleOrNamespaceKind.IsModule
12651259
then
1260+
// Contents of a module that's potentially AutoOpen are available from its parent without a prefix.
1261+
// Stay safe and as soon as the parent module is reachable, consider this module reachable as well
12661262
[| longId.GetSlice(None, Some <| longId.Length - 2); longId |]
12671263
else
1268-
[| longId |]
1264+
// 'module A.B' is equivalent to 'namespace A; module B', meaning that 'A' is opened implicitly
1265+
if
1266+
synModuleOrNamespaceKind.IsModule && longId.Length > 1
1267+
then
1268+
[| longId.GetSlice(None, Some <| longId.Length - 2); longId |]
1269+
else
1270+
[| longId |]
12691271
// TODO Temporarily disabled digging into the file's structure to avoid edge cases where another file depends on this file's namespace existing (but nothing else)
12701272
// synModuleDecls
12711273
// |> moduleDecls
@@ -1307,6 +1309,7 @@ module TopModulesExtraction =
13071309
synAccessOption,
13081310
range) ->
13091311
let idents =
1312+
// TODO Fix this by making it similar to what happens in other places where we detect AutoOpen modules
13101313
if mightHaveAutoOpen synAttributeLists then
13111314
// Contents of a module that's potentially AutoOpen are available everywhere, so treat it as if it had no name ('root' module).
13121315
[| LongIdent.Empty |]
@@ -1326,18 +1329,20 @@ module TopModulesExtraction =
13261329
synAccessOption,
13271330
range,
13281331
synModuleOrNamespaceTrivia) ->
1329-
if mightHaveAutoOpen synAttributeLists then
1330-
// Contents of a module that's potentially AutoOpen are available from its parent without a prefix.
1331-
// Stay safe and as soon as the parent module is reachable, consider this module reachable as well
1332-
[| LongIdent.Empty |]
1333-
else
1334-
// 'module A.B' is equivalent to 'namespace A; module B', meaning that 'A' is opened implicitly
13351332
if
1336-
synModuleOrNamespaceKind.IsModule && longId.Length > 1
1333+
mightHaveAutoOpen synAttributeLists && synModuleOrNamespaceKind.IsModule
13371334
then
1335+
// Contents of a module that's potentially AutoOpen are available from its parent without a prefix.
1336+
// Stay safe and as soon as the parent module is reachable, consider this module reachable as well
13381337
[| longId.GetSlice(None, Some <| longId.Length - 2); longId |]
13391338
else
1340-
[| longId |]
1339+
// 'module A.B' is equivalent to 'namespace A; module B', meaning that 'A' is opened implicitly
1340+
if
1341+
synModuleOrNamespaceKind.IsModule && longId.Length > 1
1342+
then
1343+
[| longId.GetSlice(None, Some <| longId.Length - 2); longId |]
1344+
else
1345+
[| longId |]
13411346

13421347
and moduleSigDecls (x: SynModuleSigDecl list) : Eit =
13431348
let emptyState = Eit.Nested [||]

tests/ParallelTypeCheckingTests/Tests/TestDependencyResolution.fs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@ open A
4949
let expectedEdges = [ "B.fs", [ "A.fs" ] ]
5050
assertGraphEqual deps expectedEdges
5151

52+
53+
[<Test>]
54+
let ``Another failing FCS test`` () =
55+
let files =
56+
[|
57+
"A.fsi", """
58+
namespace FSharp.Compiler.CodeAnalysis
59+
type LegacyReferenceResolver = X of int
60+
"""
61+
"B.fsi", """
62+
[<System.Obsolete("This module is not for external use and may be removed in a future release of FSharp.Compiler.Service")>]
63+
module public FSharp.Compiler.CodeAnalysis.LegacyMSBuildReferenceResolver
64+
65+
val getResolver: unit -> LegacyReferenceResolver
66+
"""
67+
|] |> buildFiles
68+
69+
let deps = DependencyResolution.detectFileDependencies files
70+
71+
let expectedEdges = ["B.fsi", ["A.fsi"]]
72+
assertGraphEqual deps expectedEdges
73+
74+
5275
[<Test>]
5376
let ``When defining a top-level module, the implicit parent namespace is taken into account when considering references to the file - .fsi pair`` () =
5477
let files =

0 commit comments

Comments
 (0)