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

DartPad crashes when redirecting a non const constructor to a const one. #34506

Closed
Soundbytes opened this issue Sep 18, 2018 · 6 comments
Closed
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. status-blocked Blocked from making progress by another (referenced) issue type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@Soundbytes
Copy link

Soundbytes commented Sep 18, 2018

DartPad crashes when redirecting a non const constructor to a const one. (see attached code)
I have to admit the parser recognized the error and showed some red signs. I went ahead anyway and thus managed to crash the compiler.

  • Dart SDK Version : 2.0
  • OS: MacOSX
  • Browser: Firefox

The code:

class _Impl {
  const _Impl() : val = 1;
  const _Impl.arg(this.val);
  final int val;
}

class Foo {
  int get a => _a.val;
  
  const Foo() : this._impl(_Impl());
  const Foo.one() : this._impl(_Impl.arg(1));  
  const Foo.arg(int a) : this._impl(_Impl.arg(a));
  
  Foo._impl(_Impl a) : _a = a;
  
  final _Impl _a;
}

main() {
  var foo = Foo.arg(2);
  print(foo.a);
}

Note that the example runs fine when instead of the Foo.arg() constructor Foo.one() or Foo() is used.


Error compiling to JavaScript:
main.dart:12:9:
Internal Error: The compiler crashed when compiling this element.
const Foo.arg(int a) : this._impl(_Impl.arg(a));
^
The compiler is broken.

When compiling the above element, the compiler crashed. It is not
possible to tell if this is caused by a problem in your program or
not. Regardless, the compiler should not crash.

The Dart team would greatly appreciate if you would take a moment to
report this problem at http://dartbug.com/new.

Please include the following information:

  • the name and version of your operating system,

  • the Dart SDK build number (2.0.0), and

  • the entire message you see here (including the full stack trace
    below as well as the source location above).

The compiler crashed: Unsupported operation: PositionalArgumentReference.evaluate
#0      PositionalArgumentReference.evaluate (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/constants/expressions.dart:1708:5)
#1      ConstructedConstantExpression.evaluate.<anonymous closure>.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/constants/expressions.dart:597:40)
#2      __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.forEach (dart:collection/runtime/libcompact_hash.dart:363:8)
#3      ConstructedConstantExpression.evaluate.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/constants/expressions.dart:596:12)
#4      EvaluationEnvironmentBase.evaluateConstructor (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/constants/evaluation.dart:112:36)
#5      ConstructedConstantExpression.evaluate (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/constants/expressions.dart:587:24)
#6      KernelConstantEnvironment._getConstantValue.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/kernel/element_map_impl.dart:1951:25)
#7      __InternalLinkedHashMap&_HashVMBase&MapMixin&_LinkedHashMapMixin.putIfAbsent (dart:collection/runtime/libcompact_hash.dart:277:23)
#8      KernelConstantEnvironment._getConstantValue (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/kernel/element_map_impl.dart:1950:22)
#9      KernelToElementMapBase.computeConstantValue (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/kernel/element_map_impl.dart:501:33)
#10     KernelToElementMapBaseMixin.getConstantValue (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/kernel/element_map_mixins.dart:329:27)
#11     KernelSsaGraphBuilder.visitConstructorInvocation (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:4692:44)
#12     ConstructorInvocation.accept (package:kernel/ast.dart:2921:36)
#13     KernelSsaGraphBuilder._normalizeAndBuildArguments.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:808:49)
#14     List.forEach (dart:core/runtime/libgrowable_array.dart:274:8)
#15     KernelSsaGraphBuilder._normalizeAndBuildArguments (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:806:35)
#16     KernelSsaGraphBuilder._inlineRedirectingInitializer (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:848:21)
#17     KernelSsaGraphBuilder._buildInitializers (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:770:9)
#18     KernelSsaGraphBuilder.buildConstructor (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:484:5)
#19     KernelSsaGraphBuilder._visitInlinedFunction (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:5490:9)
#20     KernelSsaGraphBuilder._doInline (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:5480:5)
#21     KernelSsaGraphBuilder._tryInlineMethod.doInlining.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:5175:11)
#22     KernelSsaGraphBuilder.inlinedFrom.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:662:21)
#23     CompilerDiagnosticReporter.withCurrentElement (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:750:15)
#24     KernelSsaGraphBuilder.inlinedFrom (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:660:14)
#25     KernelSsaGraphBuilder._tryInlineMethod.doInlining (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:5171:7)
#26     KernelSsaGraphBuilder._tryInlineMethod (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:5182:17)
#27     KernelSsaGraphBuilder._pushStaticInvocation (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:4102:9)
#28     KernelSsaGraphBuilder.visitConstructorInvocation (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:4731:5)
#29     ConstructorInvocation.accept (package:kernel/ast.dart:2921:36)
#30     KernelSsaGraphBuilder.visitVariableDeclaration (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:3049:24)
#31     VariableDeclaration.accept (package:kernel/ast.dart:4497:35)
#32     KernelSsaGraphBuilder.visitBlock (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:1404:17)
#33     Block.accept (package:kernel/ast.dart:3791:35)
#34     KernelSsaGraphBuilder.buildFunctionNode (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:1024:23)
#35     KernelSsaGraphBuilder.build.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:203:15)
#36     CompilerDiagnosticReporter.withCurrentElement (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:750:15)
#37     KernelSsaGraphBuilder.build (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/builder_kernel.dart:188:21)
#38     KernelSsaBuilder.build.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/kernel/kernel_backend_strategy.dart:116:22)
#39     CompilerTask.measure (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/common/tasks.dart:63:51)
#40     KernelSsaBuilder.build (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/kernel/kernel_backend_strategy.dart:102:17)
#41     SsaBuilderTask.build (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/ssa.dart:96:21)
#42     SsaFunctionCompiler.compile (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/ssa/ssa.dart:44:29)
#43     JavaScriptBackend.codegen (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/js_backend/backend.dart:700:26)
#44     KernelCodegenWorkItem.run (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/kernel/kernel_backend_strategy.dart:85:21)
#45     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:428:70)
#46     CompilerTask.measureSubtask (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/common/tasks.dart:178:35)
#47     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure>.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:428:32)
#48     CompilerTask.measureSubtask (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/common/tasks.dart:178:35)
#49     Compiler.emptyQueue.<anonymous closure>.<anonymous closure>.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:426:28)
#50     CompilerDiagnosticReporter.withCurrentElement (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:750:15)
#51     Compiler.emptyQueue.<anonymous closure>.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:424:18)
#52     EnqueuerStrategy.processWorkItem (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/enqueue.dart:501:6)
#53     CodegenEnqueuer._forEach (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/js_backend/enqueuer.dart:247:20)
#54     CodegenEnqueuer.forEach (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/js_backend/enqueuer.dart:262:5)
#55     Compiler.emptyQueue.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:420:16)
#56     CompilerTask.measureSubtask (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/common/tasks.dart:178:35)
#57     Compiler.emptyQueue (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:419:14)
#58     Compiler.processQueue.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:441:7)
#59     CompilerTask.measureSubtask (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/common/tasks.dart:178:35)
#60     Compiler.processQueue (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:438:14)
#61     Compiler.generateJavaScriptCode (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:359:5)
#62     Compiler.compileLoadedLibraries.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:385:38)
#63     CompilerTask.measureSubtask (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/common/tasks.dart:178:35)
#64     Compiler.compileLoadedLibraries (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:379:16)
#65     Compiler.runInternal (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:277:5)
<asynchronous suspension>
#66     Compiler.run.<anonymous closure>.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:216:38)
#67     new Future.sync (dart:async/future.dart:224:31)
#68     Compiler.run.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:216:20)
#69     CompilerTask.measureSubtask (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/common/tasks.dart:178:35)
#70     Compiler.run (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/compiler.dart:213:41)
#71     CompilerImpl.run.<anonymous closure>.<anonymous closure> (file:///tmp/tmpIOgzpj/dart-2.0.0/dart/pkg/compiler/lib/src/apiimpl.dart:148:22)
#72     _RootZone.runUnary (dart:async/zone.dart:1379:54)
#73     _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#74     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#75     Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#76     Future._addListener.<anonymous closure> (dart:async/future_impl.dart:351:9)
#77     _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#78     _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#79     _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:113:13)
#80     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:166:5)

@eernstg eernstg added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. web-dart2js and removed area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Sep 18, 2018
@eernstg
Copy link
Member

eernstg commented Sep 18, 2018

Thanks for reporting! I noted that there is no error for a redirecting generative constructor when it is constant and redirects to a non-constant constructor, and that's clearly a bug. Created #34509 for that.

But your example shows more, namely that dart2js crashes during compilation. I tried it out using dart2js version 2.1.0-dev.4.0, which yields

n020.dart:12:22:
Error: A constant constructor can't call a non-constant constructor.

n020.dart:13:26:
Error: A constant constructor can't call a non-constant constructor.

n020.dart:14:31:
Error: A constant constructor can't call a non-constant constructor.

Error: Compilation failed.

This is very likely to mean that the problem in dartpad will go away when a sufficiently recent version of dart2js is used there. A bit of binary searching shows that 2.1.0-dev.3.0 is the earliest version of dart2js that doesn't crash.

I don't know the schedule for getting these updates into dartpad so I'll let others comment on that, but I guess this issue could be re-purposed to basically request such an update, or it could be closed because the update will happen anyway.

Edit: @devoncarew, can you say something about the schedule?

@lrhn
Copy link
Member

lrhn commented Sep 18, 2018

All the Foo constructors should be compile-time errors. The invocation of the Impl constructor must be prefixed by const to be valid, and even then, the Impl(a) call will still be invalid because const Impl(a) is not a compile-time constant expression.

The front-end should be catching this before it reaches dart2js.

@eernstg
Copy link
Member

eernstg commented Sep 18, 2018

dart reports errors on all three constructors as it should, starting with 2.1.0-dev.3.0, so I believe that the common front end is OK. #34509 deals with the analyzer, and this issue is then only concerned with the dartpad update. So I think there is no need to create any additional issues on the front end.

@devoncarew
Copy link
Member

cc @jcollins-g

@jcollins-g
Copy link
Contributor

FYI: Currently, dartpad tracks the stable branch of Dart, so when a stable release includes this change DartPad should pick it up quickly.

@sigmundch sigmundch added the status-blocked Blocked from making progress by another (referenced) issue label Sep 25, 2018
@vsmenon vsmenon added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jul 20, 2019
@srawlins
Copy link
Member

dartpad, running now on Dart 2.5.0, does not crash in dart2js, but correctly reports static errors from dartanalyzer, and dart2js reports correct compile errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. status-blocked Blocked from making progress by another (referenced) issue type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

8 participants