Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tldrlol opened this issue Aug 23, 2015 · 5 comments
Open
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.
Milestone

Comments

@tldrlol
Copy link

tldrlol commented Aug 23, 2015

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.

@enricosada
Copy link
Contributor

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

@dsyme
Copy link
Contributor

dsyme commented Aug 25, 2015

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.

@enricosada
Copy link
Contributor

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

@dsyme
Copy link
Contributor

dsyme commented Aug 25, 2015

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

1 similar comment
@dsyme
Copy link
Contributor

dsyme commented Aug 25, 2015

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

@dsyme dsyme changed the title no initialization of modules in referenced console applications emit a warning when referencing console applications exe's without a main Jan 9, 2016
@cartermp cartermp added this to the Unknown milestone Aug 25, 2018
@dsyme dsyme added Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language. Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. and removed Feature Improvement labels Sep 16, 2021
@dsyme dsyme changed the title emit a warning when referencing console applications exe's without a main Emit a warning when referencing console applications exe's without a main Nov 4, 2021
@dsyme dsyme added Area-Diagnostics mistakes and possible improvements to diagnostics and removed Area-Compiler labels Mar 31, 2022
@vzarytovskii vzarytovskii moved this to Not Planned in F# Compiler and Tooling Jun 17, 2022
@vzarytovskii vzarytovskii reopened this Jan 5, 2024
@github-project-automation github-project-automation bot moved this from Done to In Progress in F# Compiler and Tooling Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Diagnostics mistakes and possible improvements to diagnostics Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.
Projects
Archived in project
Development

No branches or pull requests

7 participants