-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Minor hashbang-related inconsistency between the analyzer & spec and the compiler. #52331
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
Yep, I agree that the analyzer is correct. A part file cannot start with Most likely the compilers never check, they just treat all initial I don't see any particular value in making it an error, so maybe we should allow part files to start with a script tag too. |
We could do that. Just testing, it is actually possible to run a program which is determined by a part file: The part file is In other words, putting a script tag into a part makes sense for the exact same reason that it makes sense to put it into a library, and it could even be used to run the same dart program in several different ways, based on different script tags in different parts. ;-) |
Being able to use a part file as entry point sounds like being outside of the specified behavior. Unless we've been very vague in specifying, which never happens! Even then, the So we could allow a part file to start with a script tag. In the end, I didn't it'll ever matter. |
The ability to run a program from a part is accidental and only works if the |
It's implementation specific behavior, and the language specification in general does not say anything about that. But we do have this commentary in the section 'Scripts', which makes execution of parts 'atypical', if anything:
However, as @johnniwinther just mentioned, the ability to execute a part relies on using a specific kind of On top of the syntax error for the script tag in a part, each compiler/runtime can report an error if an attempt is made to execute a part (which is possible also in the case where there is no script tag anywhere). |
@johnniwinther, considering that the analyzer rejects a part with a script tag, it should be safe to make it an error with the CFE as well. In that case I'd suggest that we put the label 'implementation' on this issue and use it to be the issue that requests an implementation of this error in the CFE at some point in time where it fits the priorities. WDYT? |
SGTM |
Consider the following two files:
and
The analyzer emits an error on the keyword
part
infoo.gen.dart
that says:This seems to suggest that
foo.dart
should not compile successfully. However, we can runfoo.dart
usingdart foo.dart
and it terminates successfully and printsfoofoo
.According to the spec, the analyzer exhibits correct behavior and
foo.dart
should not compile because the grammar does not imply that a partHeader with aSCRIPT_TAG
is in the Dart language.I'm not too familiar with how the shell treats hashbangs and I might be missing some details, but, in my opinion, it looks like the way the compiler behaves allows for a cleaner separation of concerns and It might make sense to keep its behavior and adjust the analyzer and the spec:
because it would allow us to factor out the shell-related parts out of the core dart language grammar instead of only allowing
libraryDefinition
s to be members of the"shellSublanguage"
.The text was updated successfully, but these errors were encountered: