Change symbolLiteral to match actual implementation, clean up reserved words formatting #1588
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This CL changes symbol literals to allow
#void
, because we have allowed that for several years.We have had the test
tests/corelib/symbol_reserved_word_test.dart
since 2014, but it is badly flawed. In particular, it is a multi-test, but it tests many cases where a compile-time error is expected using//# ...: continued
, which means that the test will pass as long as at least one of the desired compile-time errors occur. However, some parts of the test have been executed in a meaningful manner, so we do have a history of behavior from this test. The analyzer has no current failures on this test, so it's a non-breaking change to specify the behavior that it actually tests.I've changed the test to express the intent stated in comments in that file (https://dart-review.googlesource.com/c/sdk/+/195503). In particular, it is no longer a multi-test, which fixes the logical error.
However, the test claims that
#void
andconst Symbol('void')
should not be a compile-time error, and thatnew Symbol('void')
should not be a run-time error. This is the change which is reflected by this PR.#void.foo
is flagged as an error by the analyzer and expected to be an error (so it's not a breaking change to keep considering this to be an error). It does change the reason:#void
is accepted, and.foo
is a member access on that symbol, so the error is now thatSymbol
does not have afoo
. However, that's not a breaking change.#foo.void
was a syntax error and remains a syntax error.The remaining part of
symbol_reserved_word_test.dart
tests that#word
is an error wheneverword
is a reserved word, and that is also true after this PR.I have no idea why
#void
was allowed (even though the spec never said so), but I suspect that it could be because that symbol occurs somewhere in the result of an invocation of adart:mirrors
method. In any case, it seems safe and non-breaking to add support for#void
and keep all the other reserved words an error.Finally, this PR cleans up the formatting of the reserved words and moves a couple of lexical rules away from section 'Reserved Words' and into the section where the only reference to those rules occurs.