-
Notifications
You must be signed in to change notification settings - Fork 29
#2976. Add more tests for records, factories and parenthesized expressions #3047
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
eernstg
left a comment
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.
Looks good!
I just don't understand the connection between the assertion and the test in the first one.
| /// | ||
| /// @description Checks that expressions of the form | ||
| /// `const '(' '.' id(arguments) ',' ')'` and | ||
| /// `const '(' '.' new(arguments) ',' ')'` are constant expressions. |
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.
I can't really see the connection to the assertion: The assertion is about an expression e of the form <staticMemberShorthandHead> <selector>* or '.' <identifierOrNew>? or 'const' or 'const' '.' or 'const' '.' <identifierOrNew> or 'const' '.' <identifierOrNew> <arguments> (or a bunch of other forms which are prefxies of 'const' '.' <identifierOrNew> <arguments> that I haven't already mentioned) ...
(I'm not 100% convinced we want to allow for all those forms, but anyway)
then consider the case where e also has the form 'const' '.' <identifierOrNew> <arguments>. In this case e is a constant expression, except that it is an error if it doesn't denote a constant constructor, or any argument is non-constant.
There's no reference to record literals anywhere, so where do they come from?
I think the natural thing to test would be that const .name(14) is a constant expression with context type C when C.name is a constant constructor that accepts this actual argument list.
Testing constant records is at least one step further away and doesn't actually test the use of const .name(14). It actually tests the use of .name(14) as a constant expression because .name(14) occurs in a constant context when it occurs as const (.name(14),).
So the test is OK in its own right, if the purpose is to test that constant record literals can contain static access shorthands denoting a constructor invocation, but it doesn't quite match the assertion.
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.
If we don't already have a test where a constant record literal contains a static access shorthand then we could just take a copy of this one and change the assertion, and then adjust this one to work on const .name(14) rather than const (.name(14),).
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.
The idea here was to test parenthesized expressions. To check that (.id) is treated as .id. But in case of constants const (...) is always parsed as a constant record. I think it makes sense to check that const (.id,) is still treated as a record and const (.id) is not a parenthesized constant but a syntax error. Moved to grammar tests with the apropriate assertion (can't find the better one). PTAL.
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.
Looks good, thanks!
| /// `const '(' '.' id(arguments) ',' ')'` and | ||
| /// `const '(' '.' new(arguments) ',' ')'` are constant expressions. | ||
| /// `const '(' '.' new(arguments) ',' ')'` are records containing constant | ||
| /// shorthand expressions. |
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.
Sounds good!
| /// | ||
| /// @description Checks that expressions of the form | ||
| /// `const '(' '.' id(arguments) ')'` and | ||
| /// `const '(' '.' new(arguments) ')'` are still compile-time errors. |
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.
Sounds good!
| /// | ||
| /// @description Checks that expressions of the form | ||
| /// `const '(' '.' id(arguments) ',' ')'` and | ||
| /// `const '(' '.' new(arguments) ',' ')'` are constant expressions. |
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.
Looks good, thanks!
eernstg
left a comment
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.
LGTM
2025-01-17 sgrekhov22@gmail.com Fixes dart-lang/co19#3044. Update expected errors positions for CFE (dart-lang/co19#3046) 2025-01-15 sgrekhov22@gmail.com dart-lang/co19#2976. Add more tests for records, factories and parenthesized expressions (dart-lang/co19#3047) 2025-01-15 sgrekhov22@gmail.com dart-lang/co19#2119. Actualize nnbd/static_errors_A12* description (dart-lang/co19#3048) 2025-01-14 sgrekhov22@gmail.com Fixes dart-lang/co19#3029. Add more tests for constants (dart-lang/co19#3045) 2025-01-14 sgrekhov22@gmail.com dart-lang/co19#2976. Add patterns tests (dart-lang/co19#3031) 2025-01-13 sgrekhov22@gmail.com dart-lang/co19#2976. Add more operators tests (dart-lang/co19#3043) 2025-01-13 sgrekhov22@gmail.com dart-lang/co19#3030. Add tests constants tests for String.length (dart-lang/co19#3041) 2025-01-13 sgrekhov22@gmail.com Fixes dart-lang/co19#3038. Read link to finalized object to avoid early finalization (dart-lang/co19#3042) 2025-01-10 sgrekhov22@gmail.com dart-lang/co19#2976. Add non-ambiguity tests (dart-lang/co19#3034) 2025-01-10 sgrekhov22@gmail.com dart-lang/co19#2976. Add more grammar tests (dart-lang/co19#3035) Cq-Include-Trybots: luci.dart.try:analyzer-linux-release-try Change-Id: I9feb50a33b33e85dc017d0d47829502d4f631ac7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405001 Reviewed-by: Alexander Thomas <athom@google.com> Reviewed-by: Erik Ernst <eernst@google.com> Commit-Queue: Erik Ernst <eernst@google.com> Commit-Queue: Alexander Thomas <athom@google.com>
No description provided.