fsharp
fsharp copied to clipboard
Inconsistent analysis for top-level module in F# script
In the script files, the following code is analysed in the editor without any errors
module A
let x = 3
but if you send this code to the FSI in any way (IDE, dotnet fsi file.fsx
, dotnet fsi --use:file.fsx
)
FS0010: Unexpected start of structured construct in definition. Expected '=' or other token.
error will occur
Either top-level modules must be allowed in execution with fsi, or the corresponding error must be shown when analyzed in the editor.
- .NET 8
- Rider 2024.1 RC 1, VS Code,
dotnet fsi
Namespace declaration groups and module definitions are not allowed in script fragments.
The FSharp spec (Page 298) says
script-fragment : module-elems
And module-elems
is what you find inside a module.
Having said that, I have come across this issues multiple times when moving from script to project and back. But from the little that I know about the internals of fsi, I think it won't be easy to allow modules.