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

Dart crashes with StackOverflow when compile a class with typed function unused parameter #35064

Closed
iarkh opened this issue Nov 6, 2018 · 2 comments
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.

Comments

@iarkh
Copy link
Contributor

iarkh commented Nov 6, 2018

Dart SDK Version: 2.1.0-dev.9.1
OS: Windows 10 (64 bit)

Dart crashes with StackOverflow when compile the following test example:

typedef F<X> = void Function<Y extends X>();
F<X> toF<X>(X x) => null;

typedef G<X> = void Function();
// typedef G<X> = X Function();
class A<X extends G<A<X>>> {}

main() {
  A source;
  var fsource = toF(source);
  F<A<G<A<dynamic>>>> target = fsource;

  F<A<G<A<Null>>>> target0 = fsource;

  F<A<dynamic>> target1 = fsource;    // compile-error
  F<A<G<dynamic>>> target2 = fsource;
  F<A<G<A<dynamic>>>> target3 = fsource;
  F<A<G<A<G<dynamic>>>>> target4 = fsource;
}

Analyzer is OK here, it produces compile error on the line 15, no crash with this.

Please note that:

  • Dart does not crash here if I comment line 4 and uncomment line 5, i.e. if I use covariant or contravariant function parameter (typedef G<X> = X Function()) instead of unused one (typedef G<X> = void Function()).
  • Dart does not crash if I comment line 18 in the source code above, i.e. crash does not happen for F<A<dynamic>>, F<A<G<dynamic>>>, F<A<G<A<dynamic>>>> variables and dart crashes for F<A<G<A<G<dynamic>>>>> and so on.

Dart sample output is:

Crash when compiling file:///D:/DART/sdk/tests/co19/src/LanguageFeatures/Instantiate-to-bound/class/dynamic/test.dart,
at character offset 179:
Stack Overflow
#0 __CompactLinkedIdentityHashMap&_HashFieldBase&MapMixin&_LinkedHashMapMixin._getValueOrData (dart:collection/runtime/libcompact_hash.dart:324:3)
#1 __CompactLinkedIdentityHashMap&_HashFieldBase&MapMixin&_LinkedHashMapMixin.containsKey (dart:collection/runtime/libcompact_hash.dart:348:53)
#2 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:229:31)
#3 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:241:26)
#4 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#5 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#6 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#7 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#8 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#9 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#10 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#11 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#12 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#13 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#14 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#15 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#16 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#17 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#18 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#19 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#20 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#21 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#22 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#23 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#24 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#25 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#26 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#27 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#28 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#29 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#30 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#31 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#32 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#33 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#34 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#35 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#36 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#37 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#38 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#39 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#40 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#41 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#42 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#43 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
...
...
#4574 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#4575 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#4576 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#4577 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#4578 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#4579 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#4580 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#4581 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#4582 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:305:33)
#4583 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:256:23)
#4584 TypeEnvironment.findBoundViolations (package:kernel/type_environment.dart:241:26)
#4585 KernelLibraryBuilder.checkBoundsInVariableDeclaration (package:front_end/src/fasta/kernel/kernel_library_builder.dart:1640:47)
#4586 BodyBuilder.pushNewLocalVariable (package:front_end/src/fasta/kernel/body_builder.dart:1967:13)
#4587 Parser.parseVariableInitializerOpt (package:front_end/src/fasta/parser/parser.dart:1944:39)
#4588 Parser.parseOptionallyInitializedIdentifier (package:front_end/src/fasta/parser/parser.dart:4965:13)
#4589 Parser.parseExpressionStatementOrDeclarationAfterModifiers (package:front_end/src/fasta/parser/parser.dart:4946:13)
#4590 Parser.parseStatementX (package:front_end/src/fasta/parser/parser.dart:3477:14)
#4591 Parser.parseFunctionBody (package:front_end/src/fasta/parser/parser.dart:3467:20)
#4592 DietListener.buildFunctionBody (package:front_end/src/fasta/source/diet_listener.dart:826:14)
#4593 DietListener.endTopLevelMethod (package:front_end/src/fasta/source/diet_listener.dart:303:5)
#4594 Parser.parseTopLevelMethod (package:front_end/src/fasta/parser/parser.dart:2289:14)
#4595 Parser.parseTopLevelMemberImpl (package:front_end/src/fasta/parser/parser.dart:2190:14)
#4596 Parser.parseTopLevelDeclarationImpl (package:front_end/src/fasta/parser/parser.dart:481:14)
#4597 Parser.parseUnit (package:front_end/src/fasta/parser/parser.dart:336:15)
#4598 SourceLoader.buildBody (package:front_end/src/fasta/source/source_loader.dart:253:14)
#4599 _asyncThenWrapperHelper. (dart:async/runtime/libasync_patch.dart:77:64)
#4600 _rootRunUnary (dart:async/zone.dart:1132:38)
#4601 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#4602 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#4603 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#4604 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#4605 Future._complete (dart:async/future_impl.dart:476:7)
#4606 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#4607 _AsyncAwaitCompleter.complete. (dart:async/runtime/libasync_patch.dart:33:20)
#4608 _rootRun (dart:async/zone.dart:1124:13)
#4609 _CustomZone.run (dart:async/zone.dart:1021:19)
#4610 _CustomZone.bindCallback. (dart:async/zone.dart:947:23)
#4611 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#4612 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#4613 _runPendingImmediateCallback (dart:isolate/runtime/libisolate_patch.dart:115:13)
#4614 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:172:5)

#0 DietListener.buildFunctionBody (package:front_end/src/fasta/source/diet_listener.dart:834:7)
#1 DietListener.endTopLevelMethod (package:front_end/src/fasta/source/diet_listener.dart:303:5)
#2 Parser.parseTopLevelMethod (package:front_end/src/fasta/parser/parser.dart:2289:14)
#3 Parser.parseTopLevelMemberImpl (package:front_end/src/fasta/parser/parser.dart:2190:14)
#4 Parser.parseTopLevelDeclarationImpl (package:front_end/src/fasta/parser/parser.dart:481:14)
#5 Parser.parseUnit (package:front_end/src/fasta/parser/parser.dart:336:15)
#6 SourceLoader.buildBody (package:front_end/src/fasta/source/source_loader.dart:253:14)

#7 Loader.buildBodies (package:front_end/src/fasta/loader.dart:181:15)

#8 KernelTarget.buildComponent. (package:front_end/src/fasta/kernel/kernel_target.dart:307:20)

#9 withCrashReporting (package:front_end/src/fasta/crash.dart:122:24)

#10 KernelTarget.buildComponent (package:front_end/src/fasta/kernel/kernel_target.dart:305:12)

#11 IncrementalCompiler.computeDelta. (package:front_end/src/fasta/incremental_compiler.dart:257:26)

#12 CompilerContext.runInContext.. (package:front_end/src/fasta/compiler_context.dart:120:46)
#13 new Future.sync (dart:async/future.dart:224:31)
#14 CompilerContext.runInContext. (package:front_end/src/fasta/compiler_context.dart:120:19)
#15 _rootRun (dart:async/zone.dart:1124:13)
#16 _CustomZone.run (dart:async/zone.dart:1021:19)
#17 _runZoned (dart:async/zone.dart:1516:10)
#18 runZoned (dart:async/zone.dart:1463:12)
#19 CompilerContext.runInContext (package:front_end/src/fasta/compiler_context.dart:119:12)
#20 IncrementalCompiler.computeDelta (package:front_end/src/fasta/incremental_compiler.dart:108:20)

#21 IncrementalCompiler.compile (package:vm/incremental_compiler.dart:47:44)

#22 IncrementalCompilerWrapper.compileInternal (file:///E:/b/build/slave/dart-sdk-windows-dev/build/sdk/pkg/vm/bin/kernel_service.dart:155:28)

#23 Compiler.compile. (file:///E:/b/build/slave/dart-sdk-windows-dev/build/sdk/pkg/vm/bin/kernel_service.dart:121:31)

#24 new Future. (dart:async/future.dart:176:37)
#25 _rootRun (dart:async/zone.dart:1120:38)
#26 _CustomZone.run (dart:async/zone.dart:1021:19)
#27 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
#28 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
#29 _rootRun (dart:async/zone.dart:1124:13)
#30 _CustomZone.run (dart:async/zone.dart:1021:19)
#31 _CustomZone.bindCallback. (dart:async/zone.dart:947:23)
#32 Timer._createTimer. (dart:async/runtime/libtimer_patch.dart:21:15)
#33 _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
#34 _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#35 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)

Process finished with exit code 252

@mit-mit mit-mit added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Nov 7, 2018
@mit-mit
Copy link
Member

mit-mit commented Nov 7, 2018

cc @kmillikin, not sure if this is important for 2.1?

@srawlins
Copy link
Member

srawlins commented Aug 6, 2019

I suspect this had to do with missing front-end errors. It now errors gracefully:

$ $ dartanalyzer 35064.dart 
Analyzing 35064.dart...
  error • A value of type 'void Function<Y extends A<void Function()>>()' can't be assigned to a variable of type 'void Function<Y extends A<dynamic>>()' at 35064.dart:16:27 • invalid_assignment
1 error found.

$ dart 35064.dart 
35064.dart:16:27: Error: A value of type 'void Function<Y extends A<void Function()>>()' can't be assigned to a variable of type 'void Function<Y extends A<dynamic>>()'.
 - 'A' is from '35064.dart'.
Try changing the type of the left hand side, or casting the right hand side to 'void Function<Y extends A<dynamic>>()'.
  F<A<dynamic>> target1 = fsource; // compile-error

@srawlins srawlins closed this as completed Aug 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.
Projects
None yet
Development

No branches or pull requests

3 participants