|
|
Created:
6 years, 7 months ago by gbracha Modified:
6 years, 7 months ago CC:
reviews_dartlang.org Visibility:
Public. |
Descriptionmain function may take an argument.
R=lrn@google.com
Committed: https://code.google.com/p/dart/source/detail?r=36450
Patch Set 1 #Patch Set 2 : #
Total comments: 1
Patch Set 3 : #
Total comments: 2
Patch Set 4 : #Messages
Total messages: 10 (0 generated)
Handling of main(), revised for two arguments.
What happens in this case: main({a}) {} As far as I can tell, this is supposed to be invoked as main([]), which should cause an error. This is not the VM's current behavior. Cheers, Peter
https://codereview.chromium.org/280473004/diff/20001/docs/language/dartLangSp... File docs/language/dartLangSpec.tex (right): https://codereview.chromium.org/280473004/diff/20001/docs/language/dartLangSp... docs/language/dartLangSpec.tex:5226: First, $S$ is compiled as a library as specified above. Then, the top-level function \code{main} that is in the exported namespace of $S$ is invoked. If \code{main} has no formal parameters, it is invoked with no arguments. Otherwise if \code{main} has exactly one parameter, it is invoked with a single actual argument whose type implements \code{List$<$String$>$}. Otherwise \code{main} is invoked with the following two actual arguments: I believe the way it is implemented, and the way it is partially specified in the documentation for Isolate.spawnUri (https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-isolate....), is that: - if the main function's type is a subtype of (dynamic,dynamic)->dynamic, then it is called with two arguments. - otherwise, if the main function's type is a subtype of (dynamic)->dynamic, then it is called with one argument, - otherwise it is called with no arguments. This specification differs from this if there are optional parameters : main([a, b, c]); // two arguments main(a, [b, c]); // two arguments main(a, b, [c]); // two arguments main([a]); // one argument main(a, b, {x:42}); // two arguments main(a, {x:42}); // one argument main({x: 42}); // zero arguments All of these should be valid and cause no warning. Recursively calling main with extra parameters isn't good style, but it is allowed. More than two required parameters is still a static warning and runtime error.
On 2014/05/15 20:44:47, Lasse Reichstein Nielsen wrote: > https://codereview.chromium.org/280473004/diff/20001/docs/language/dartLangSp... > File docs/language/dartLangSpec.tex (right): > > https://codereview.chromium.org/280473004/diff/20001/docs/language/dartLangSp... > docs/language/dartLangSpec.tex:5226: First, $S$ is compiled as a library as > specified above. Then, the top-level function \code{main} that is in the > exported namespace of $S$ is invoked. If \code{main} has no formal parameters, > it is invoked with no arguments. Otherwise if \code{main} has exactly one > parameter, it is invoked with a single actual argument whose type implements > \code{List$<$String$>$}. Otherwise \code{main} is invoked with the following > two actual arguments: > I believe the way it is implemented, and the way it is partially specified in > the documentation for Isolate.spawnUri > (https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart-isolate....), > is that: > - if the main function's type is a subtype of (dynamic,dynamic)->dynamic, then > it is called with two arguments. > - otherwise, if the main function's type is a subtype of (dynamic)->dynamic, > then it is called with one argument, > - otherwise it is called with no arguments. That isn't literally what the dart doc says, but it is compatible with the spec. > > This specification differs from this if there are optional parameters : Actually, it only differs for named arguments. So instead of saying "no formal parameter" it should say "no positional parameter" and for the two parameter case it should say two positional parameters. > main([a, b, c]); // two arguments > main(a, [b, c]); // two arguments > main(a, b, [c]); // two arguments > main([a]); // one argument > main(a, b, {x:42}); // two arguments > main(a, {x:42}); // one argument > main({x: 42}); // zero arguments > All of these should be valid and cause no warning. Recursively calling main with > extra parameters isn't good style, but it is allowed. > > More than two required parameters is still a static warning and runtime error.
PTAL
LGTM.
https://codereview.chromium.org/280473004/diff/40001/docs/language/dartLangSp... File docs/language/dartLangSpec.tex (right): https://codereview.chromium.org/280473004/diff/40001/docs/language/dartLangSp... docs/language/dartLangSpec.tex:5226: First, $S$ is compiled as a library as specified above. Then, the top-level function \code{main} that is in the exported namespace of $S$ is invoked. If \code{main} has no positional parameters, it is invoked with no arguments. Otherwise if \code{main} has exactly one positional parameter, it is invoked with a single actual argument whose type implements \code{List$<$String$>$}. Otherwise \code{main} is invoked with the following two actual arguments: It is not clear to me what "whose type implements List<String>" means. Does that refer to the static type or the runtime type? https://codereview.chromium.org/280473004/diff/40001/docs/language/dartLangSp... docs/language/dartLangSpec.tex:5228: \item An object whose type implements \code{List$<$String$>$}. Ditto.
On 2014/05/19 12:13:08, ahe wrote: > https://codereview.chromium.org/280473004/diff/40001/docs/language/dartLangSp... > File docs/language/dartLangSpec.tex (right): > > https://codereview.chromium.org/280473004/diff/40001/docs/language/dartLangSp... > docs/language/dartLangSpec.tex:5226: First, $S$ is compiled as a library as > specified above. Then, the top-level function \code{main} that is in the > exported namespace of $S$ is invoked. If \code{main} has no positional > parameters, it is invoked with no arguments. Otherwise if \code{main} has > exactly one positional parameter, it is invoked with a single actual argument > whose type implements \code{List$<$String$>$}. Otherwise \code{main} is invoked > with the following two actual arguments: > It is not clear to me what "whose type implements List<String>" means. Does > that refer to the static type or the runtime type? > > https://codereview.chromium.org/280473004/diff/40001/docs/language/dartLangSp... > docs/language/dartLangSpec.tex:5228: \item An object whose type implements > \code{List$<$String$>$}. > Ditto. Ok, changed both occurrences to say 'runtime type'.
Message was sent while issue was closed.
Committed patchset #4 manually as r36450 (presubmit successful). |