-
Notifications
You must be signed in to change notification settings - Fork 1.7k
main can take up to two arguments #18812
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
Comments
I suggest a rule along these lines: Given these typedefs: typedef ZeroParameters(); typedef OneParameter(a); If main is a top-level function and a subtype of OneParameter, it is invoked with one argument whose runtime type is a subtype of List<String>. Otherwise, if main is a top-level function and a subtype of ZeroParameters, it is invoked with no arguments. Otherwise, it is a static (type?) warning and a runtime error. This leads to this test case: main( a /// 01: ok [a] /// 20: ok {a} /// 41: ok ) { Right now, dart2js fails most of these cases (it reports compile time errors). I have a CL which makes dart2js behave as described above. cc @larsbak. |
Update: the VM doesn't fail 03. |
cc @johnniwinther. |
Ok, the latest spec has a fix for this. Added Done label. |
I took a look at the latest spec, it says: "First, That seems to match what I said in comment #1. Since then I have learned why dart2js and the VM accepts a second parameter to main. This is used from Isolate.spawnUri https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-isolate.Isolate#id_spawnUri My comment #1 can be extended to handle the second parameter: Given these typedefs: typedef ZeroParameters(); typedef OneParameter(a); typedef TwoPwarmeters(a,b); If main is a top-level function and a subtype of TwoParameter, it is invoked with two arguments, the first argument's runtime type is a subtype of List<String>, the second argument depends on the environment. Rationale: see Isolate.spawnUri. Otherwise, if main is a top-level function and a subtype of OneParameter, it is invoked with one argument whose runtime type is a subtype of List<String>. Otherwise, if main is a top-level function and a subtype of ZeroParameters, it is invoked with no arguments. Otherwise, it is a static (type?) warning and a runtime error. cc @lrhn. |
Marked this as blocking #5683. |
Ok, I've revised the spec to account for the second arguments as well. See https://codereview.chromium.org/280473004/ Added Accepted label. |
Unmarked this as blocking #5683. |
Added Done label. |
From https://www.dartlang.org/docs/spec/latest/dart-language-specification.html#h.ey3rvr2kjush:
"Then, the top level function main that is in the exported namespace of S is invoked with no arguments. It is a run time error if S does not declare or import a top level function main."
However, dart2js and the VM agree that the method can be passed up to two arguments. I'm not sure exactly what they are, which is why I looked at the specification.
The text was updated successfully, but these errors were encountered: