{"action":"opened","issue":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/27617","repository_url":"https://api.github.com/repos/dart-lang/sdk","labels_url":"https://api.github.com/repos/dart-lang/sdk/issues/27617/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/sdk/issues/27617/comments","events_url":"https://api.github.com/repos/dart-lang/sdk/issues/27617/events","html_url":"https://github.com/dart-lang/sdk/issues/27617","id":184035898,"number":27617,"title":"Redirection from const to non-const constructor partially allowed with weird behavior","user":{"login":"yjbanov","id":211513,"avatar_url":"https://avatars.githubusercontent.com/u/211513?v=3","gravatar_id":"","url":"https://api.github.com/users/yjbanov","html_url":"https://github.com/yjbanov","followers_url":"https://api.github.com/users/yjbanov/followers","following_url":"https://api.github.com/users/yjbanov/following{/other_user}","gists_url":"https://api.github.com/users/yjbanov/gists{/gist_id}","starred_url":"https://api.github.com/users/yjbanov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yjbanov/subscriptions","organizations_url":"https://api.github.com/users/yjbanov/orgs","repos_url":"https://api.github.com/users/yjbanov/repos","events_url":"https://api.github.com/users/yjbanov/events{/privacy}","received_events_url":"https://api.github.com/users/yjbanov/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-19T18:15:06Z","updated_at":"2016-10-19T18:15:06Z","closed_at":null,"body":"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!\r\n\r\nExample (code in comments shows other interesting situations):\r\n\r\n```\r\nclass Foo {\r\n  final String greeting;\r\n\r\n  Foo._(this.greeting) {\r\n    print('>>> checking!');\r\n    i = 1;\r\n    if (greeting == null) throw 'null!!!';\r\n  }\r\n\r\n  const Foo.hi() : this._('hi');\r\n  const Foo.nullses() : this._(null);\r\n}\r\n\r\nint i = 0;\r\nconst h = const Foo.hi();\r\n//const n = const Foo.nullses();\r\n\r\nmain() {\r\n//  print(new Foo.hi().greeting);\r\n//  print(new Foo.nullses().greeting);\r\n\r\n  print(h.greeting);\r\n  print(i);\r\n//  print(n.greeting);\r\n}\r\n```\r\n\r\n[Dartpad](https://dartpad.dartlang.org/0fe524eb39ef6d799b2a98f6cf733cf7)\r\n\r\nThe code above doesn't result in analyzer warnings.\r\n\r\nIn dart2js it crashes with:\r\n\r\n```\r\nError compiling to JavaScript:\r\n[error on line 9] 'const' constructor cannot call a non-const constructor.\r\n```\r\n\r\nIn Dart VM (in both checked and unchecked modes) the code runs fine and prints:\r\n\r\n```\r\n>>> checking!\r\nhi\r\n1\r\n```\r\n"}}
{"actor":{"display_login":"yjbanov"}}