Skip to content

Commit ee881e9

Browse files
committed
Check if the module appears to be incorrectly nested based on indentation
1 parent 0f7c23c commit ee881e9

File tree

6 files changed

+41
-0
lines changed

6 files changed

+41
-0
lines changed

src/Compiler/pars.fsy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,14 @@ moduleDefnsOrExpr:
12711271

12721272
/* A sequence of definitions in a namespace or module */
12731273
moduleDefns:
1274+
| moduleDefnOrDirective moduleDefnOrDirective
1275+
{ match $1, $2 with
1276+
| [SynModuleDecl.Types _], [SynModuleDecl.NestedModule(_, _, _, _, _, { ModuleKeyword = Some m })] ->
1277+
// Check if the module appears to be incorrectly nested based on indentation
1278+
errorR(Error(FSComp.SR.parsInvalidDeclarationSyntax(), m))
1279+
$1 @ $2
1280+
| _ -> $1 @ $2 }
1281+
12741282
| moduleDefnOrDirective moduleDefns
12751283
{ $1 @ $2 }
12761284

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Module
2+
3+
type IFace =
4+
abstract F : int -> int
5+
module M =
6+
let f () = ()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Module
2+
3+
type C () =
4+
member _.F () = 3
5+
module M2 =
6+
let f () = ()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Module
2+
3+
type U =
4+
| A
5+
| B
6+
module M3 =
7+
let f () = ()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Module
2+
3+
type R =
4+
{ A : int }
5+
module M4 =
6+
let f () = ()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Module
2+
3+
type IFace =
4+
interface
5+
abstract F : int -> int
6+
module M =
7+
let f () = f ()
8+
end

0 commit comments

Comments
 (0)