fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Inconsistent analysis for top-level module in F# script

Open DedSec256 opened this issue 10 months ago • 1 comments

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

image image image

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

DedSec256 avatar Apr 04 '24 17:04 DedSec256

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.

Martin521 avatar Apr 04 '24 21:04 Martin521