Skip to content
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

VM allows assignment in assert. #17682

Closed
lrhn opened this issue Mar 21, 2014 · 4 comments
Closed

VM allows assignment in assert. #17682

lrhn opened this issue Mar 21, 2014 · 4 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Mar 21, 2014

Grammar of assert statements is:

'assert' '(' conditionalExpression ')' ';'

This does not allow assignment expressions directly as the expression.
The VM allows the syntax:

assert(x = true);

Analyzer now catches the syntax error.

@DartBot
Copy link

DartBot commented Apr 26, 2014

This comment was originally written by @chalin


Related: https://code.google.com/p/dart/issues/detail?id=12289

@lrhn lrhn added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. labels Apr 26, 2014
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@mhausner
Copy link
Contributor

dart2js also allows assert(x = true). Both implementations are wrong. I suspect that there is code that may depend on this, maybe on purpose. For example, tests/standalone/io/file_constructor_test.dart.

void main() {
  bool developerMode = false;
  assert(developerMode = true);
  ....
  if (developerMode) ....

@mhausner
Copy link
Contributor

@floitschG, please determine whether the language spec should be updated, or the two implementations should be fixed.

@eernstg
Copy link
Member

eernstg commented Jul 12, 2016

We discussed this issue in the language team and came up with the following analysis which concludes that we will switch to assert(expression): https://gist.github.com/eernstg/50a327addd96035d5393a507c0ea2d9a.

This means that the vm and dart2js already implement the right semantics, but the analyzer should be adjusted. Created a new issue for the adjustment of the analyzer and one for the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants