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

Redirection from const to non-const constructor partially allowed with weird behavior #27617

Closed
yjbanov opened this issue Oct 19, 2016 · 3 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

Comments

@yjbanov
Copy link

yjbanov commented Oct 19, 2016

It seems the analyzer (both strong and weak) and the Dart VM allow redirecting from a const constructor to a non-const constructor, but dart2js doesn't. Dart VM even allows printing from such a constructor and side-effects!

Example (code in comments shows other interesting situations):

class Foo {
  final String greeting;

  Foo._(this.greeting) {
    print('>>> checking!');
    i = 1;
    if (greeting == null) throw 'null!!!';
  }

  const Foo.hi() : this._('hi');
  const Foo.nullses() : this._(null);
}

int i = 0;
const h = const Foo.hi();
//const n = const Foo.nullses();

main() {
//  print(new Foo.hi().greeting);
//  print(new Foo.nullses().greeting);

  print(h.greeting);
  print(i);
//  print(n.greeting);
}

Dartpad

The code above doesn't result in analyzer warnings.

In dart2js it crashes with:

Error compiling to JavaScript:
[error on line 9] 'const' constructor cannot call a non-const constructor.

In Dart VM (in both checked and unchecked modes) the code runs fine and prints:

>>> checking!
hi
1
@a-siva a-siva added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Oct 19, 2016
mhausner added a commit that referenced this issue Oct 19, 2016
Const constructor can only redirect to another const constructor.

BUG=#27617
R=regis@google.com

Review URL: https://codereview.chromium.org/2439593003 .
@mhausner
Copy link
Contributor

Fixed in f73ea62

@yjbanov
Copy link
Author

yjbanov commented Oct 20, 2016

Thanks for the quick VM fix! However, f73ea62 does not fix the analyzer. Reopening (but ok if that's tracked as a separate issue).

@yjbanov yjbanov reopened this Oct 20, 2016
@mhausner mhausner added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. and removed area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. labels Oct 20, 2016
@mhausner mhausner removed their assignment Oct 20, 2016
@mhausner
Copy link
Contributor

Recycling the bug. Remaining issue is with Analyzer.

@bwilkerson bwilkerson added P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 21, 2016
@bwilkerson bwilkerson added this to the Dart2.1 milestone Sep 4, 2018
@bwilkerson bwilkerson modified the milestones: Dart2.1, PostDart2.1 Sep 4, 2018
@aadilmaan aadilmaan modified the milestones: Future, D25 Release Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants