Skip to content

Analyzer: no error for using assertions in redirecting generative constructors #37867

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

Closed
LongCatIsLooong opened this issue Aug 14, 2019 · 1 comment
Labels
legacy-area-analyzer Use area-devexp instead.

Comments

@LongCatIsLooong
Copy link

On dartPad or with my local SDK, the following code snippet does not trigger an analyzer warning/error, but fails to compile:

void main() {
  print(A.half(4));
}

class A {
  final int x;
  A(this.x);
  A.half(int x):
    assert(x % 2 == 0),
    this(x ~/ 2);
}

dart --version:

Dart VM version: 2.5.0-dev.1.0.flutter-0ca1582afd (Thu Jul 25 23:50:46 2019 +0000) on "linux_x64"

@a-siva a-siva added the legacy-area-analyzer Use area-devexp instead. label Aug 14, 2019
@srawlins
Copy link
Member

For reference, dart2js produces the following error while compiling the code above:

Error: Can't have other initializers together with 'this'.
main.dart:8:3:
Error: Final field 'x' is not initialized by this constructor.
A.half(int x):
^^^^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead.
Projects
None yet
Development

No branches or pull requests

3 participants