Skip to content
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

Improve error reporting: using EntryPoint attribute in an F# script #1431

Closed
Tracked by #1103
anton-pt opened this issue Aug 13, 2016 · 7 comments
Closed
Tracked by #1103

Improve error reporting: using EntryPoint attribute in an F# script #1431

anton-pt opened this issue Aug 13, 2016 · 7 comments
Labels
Feature Improvement good first issue Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.
Milestone

Comments

@anton-pt
Copy link

What

Running the code:

[<EntryPoint>]
let main argv =
    printfn "Hello, world!"   
    0

in FSI produces the output
val main : argv:string [] -> int
but doesn't actually invoke the function.

Why

Some beginners may be unsure about how F# scripts and FSI work and may run some code from an application which has an EntryPoint into FSI. This happened recently to a former colleague.

How

Using the EntryPoint attribute in FSI should produce a compiler warning indicating that it won't be invoked automatically.

@KevinRansom
Copy link
Member

Agreed.

@isaacabraham
Copy link
Contributor

@anton-pt can you suggest an error message that should be displayed - we should be able to come up with one easily, and then this can be marked as up for grabs.

@anton-pt
Copy link
Author

How about something like this?

Warning: defined function [f] marked as EntryPoint was not invoked. Execute [f argv] in order to invoke [f] with the appropriate string array of command line arguments.

@bisen2
Copy link

bisen2 commented Jul 12, 2021

It seems to me that FSI should implicitly run a method marked with the EntryPoint attribute. For example:

[<EntryPoint>]
let main argv =
    printfn "Hello, World!"
    0

should be equivalent to

let main argv =
    printfn "Hello, World!"
    0

main fsi.CommandLineArgs

@vzarytovskii
Copy link
Member

vzarytovskii commented Jul 12, 2021

We already have an implicit entry point created in scripts, adding some different behaviour, based on attribute would be confusing and, probably, a breaking change, for example consider the following code:

[<EntryPoint>]
let main argv =
    printfn "Hello, World!"
    0

#if INTERACTIVE
main fsi.CommandLineArgs
#endif

main will be executed twice, since second one is going to be generated by compiler.

I think, a warning should be produced instead (as it was suggested originally).

@dsyme
Copy link
Contributor

dsyme commented Jul 13, 2021

I think, a warning should be produced instead (as it was suggested originally).

Yes, it makes sense

@dsyme dsyme added the Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language. label Sep 16, 2021
@KathleenDollard
Copy link

If we're just looking for text here, working from @anton-pt 's suggestion:

Function with [<EntryPoint>] are not invoked in FSI. [f] was not invoked. Execute [f <args>] in order to invoke [f] with the appropriate string array of command line arguments.

I assume the [f] will be replaced with the fuction name. I think "argv" is confusing if the user needs to type args there, so the will hopefully inspire the programmer to type real values there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Improvement good first issue Theme-Simple-F# A cross-community initiative called "Simple F#", keeping people in the sweet spot of the language.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

9 participants