fsharp icon indicating copy to clipboard operation
fsharp copied to clipboard

Emit a warning when referencing console applications exe's without a main

Open tldrlol opened this issue 10 years ago • 5 comments

Create a solution with two Console Application projects:

ConsoleApplication1\Program.fs:

module SharedValue
let hello = "Hello" |> id

ConsoleApplication2\Program.fs (references ConsoleApplication1)

match SharedValue.hello with
| null -> printfn "SharedValue.hello is null!"
| _    -> printfn "all good"

Expected output: all good Actual output: SharedValue.hello is null!

needless to say, getting a null value from an F# project is quite surprising.

Changing the type of ConsoleApplication1 to a Library fixes this.

tldrlol avatar Aug 23 '15 11:08 tldrlol

i think is the same problem as fsharp/fsharp#326 , the console project doesn't initialize hello because you dont declare/execute the main function.

see @latkin 's comment for detailed explaination and workaround

@latkin @dsyme we need to add a warning? with c# you can reference the console app without problem, so is a bit unintuitive/annoying

enricosada avatar Aug 25 '15 07:08 enricosada

Yrs, an explicit Main is required, and this is currently considered by design, for better or worse.

Adding a warning on referencing such a component may well be feasible.

dsyme avatar Aug 25 '15 14:08 dsyme

What's best?

  1. warning (error?) if a console app doesnt have a main
  2. warning if a referenced fsharp assembly (discriminate on .exe extension?) doesn't have a main

enricosada avatar Aug 25 '15 14:08 enricosada

#2 - emit an attribute or other bit when no main on .exe, and detect that when the component is referenced

dsyme avatar Aug 25 '15 16:08 dsyme

#2 - emit an attribute or other bit when no main on .exe, and detect that when the component is referenced

dsyme avatar Aug 25 '15 16:08 dsyme