-
Notifications
You must be signed in to change notification settings - Fork 223
Propose rules about main
for null-safety
#1146
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this actually differ from what we have now?
The only difference I see is that we can now pass more arguments if we want to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review response.
@lrhn wrote:
It specifies that it is a compile-time error to have a first positional argument whose type isn't a supertype of It allows implementations to add their own constraints on the signature of Finally, it specifies that dynamic errors must occur such that the invocation of |
@leafpetersen, @rakudrama, @natebosch, do you have further comments on this PR? |
following: | ||
|
||
Let _L_ be a library that exports a declaration _D_ named `main`. It is a | ||
compile-time error unless _D_ is a function declaration. It is a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This excludes getters, right? co19/Language/Libraries_and_Scripts/Scripts/top_level_main_t05 seems to assume it doesn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is intended to exclude getters. The old version of this text in section Scripts
said explicitly in commentary that we couldn't have a 'top-level getter or field named main
', and we did not discuss nor intend to change that when this spec change was landed.
However, section 'Functions' implies that 'function' includes getters, setters, constructors, and "functions" (no, we don't have a separate term for the ones that have a <formalParameterList>
and aren't constructors, I had a CL a long time ago to fix that, but it hasn't been landed). So the text should say unless _D_ is a non-getter function declaration
. It can't be a top-level constructor and a setter can't have the name main
, so that should be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: #1248
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When calling main
from external code, e.g. JavaScript, it is necessary to convert arguments. We can't just say that main
is called dynamically from 'outside'. This conversion happens in the context of the program but before entering main
, e.g. needs to access the type List<String>
for that program. This interstitial place a special place that we want to constrain heavily in a platform dependent way. For dart2js we want limit the conversion to just Array
-to-List<String>
, for which we need to know the static type of the entry point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rakudrama does line 920 not address your concerns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does. I was just adding colour for Johnni.
This is a proposal for new rules about
main
, adding a new section in the null safety spec (which will replace the section 'Scripts' in the language specification in the future).Potentially noteworthy aspects (compared to this):
This proposal maintains that the initial function has the name
main
. I think it's helpful for developers to know for sure that the initial function has this name, so that they don't suddenly have to use some other name, just because they have switched to use a different compiler.This proposal still defines the term script; however, it is now a very straightforward concept. If we think the word 'script' sounds too "PHP-ish" then we can rename it (here, and later in the language specification in general), but it seems reasonable to be able to talk about the ability to be the provider of the function that defines what it means to run a program (the "initial function").
I have preserved the specification of how to invoke
main
(with 2, 1, or 0 arguments), but broadened it to allow implementations to pass additional arguments. This means that an embedder can allow or requiremain
to have additional optional parameters (positional or named), and it can pass whatever actual arguments it wants to those additional parameters.But we do maintain that
T main()
for anyT
,T main(U u)
whereList<String> <: U
, andT main(U u, V v)
must work (except for the catchall clause that "implementations can have arbitrary extra constraints on the signature ofmain
"). Also, all invocations must enforce the declared types, and we do statically prevent weird signatures likevoid main(int i)
andvoid main(arg1, arg2, arg3)
.