dotnet / dotnet/fsharp

Improve error reporting: importing modules from an assembly compiled as Exe but without explicit EntryPoint should raise a warning

Open
#1,371 12 comments 0 reactions 0 assignees View on GitHub
Feature Improvement Theme-Simple-F#
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

## what

F# users not acquainted with module static initialization semantics in exe project (which apparently differ from library project) might expect a different result when doing this:
## steps

``` shell
C:\tmp\repro>more main.fs
```

``` fsharp
module Foo
type Buildable = Buildable of obj
let o = Buildable null
```

``` shell
C:\tmp\repro>fsc main.fs
Microsoft (R) F# Compiler version 14.0.23413.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

C:\tmp\repro>more test.fsx
```

``` fsharp
#r @"main.exe"
printfn "%A" Foo.o
```

``` shell
C:\tmp\repro>fsi test.fsx

C:\tmp\repro>
```
## Actual results

The static type initializer for module Foo wasn't executed and `Foo.o` will always remain null.
## Expected results

If we want to preserve that behaviour, I think a warning when referencing a .exe containing F# modules would help user to understand that modules might not be initialized as intended.

If we could fix the behaviour while maintaining compatibility / non breaking change, that would IMHO be ideal.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.