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

Fasta crashes under specific conditions in anonymous mixin applications #34511

Closed
chloestefantsova opened this issue Sep 18, 2018 · 2 comments
Closed
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. P2 A bug or feature request we're likely to work on
Milestone

Comments

@chloestefantsova
Copy link
Contributor

Consider the following program:

class A<X, Y> {}

class B<Z> extends Object with A<void Function(Z), int> {}

main() {}

When being compiled with the current repo checkout, it produces the following output:

$ pkg/front_end/tool/fasta compile --strong --dump-ir /tmp/qwerty.dart
library;
import self as self;
import "dart:core" as core;

class A<X extends core::Object = dynamic, Y extends core::Object = dynamic> extends core::Object {
  synthetic constructor •() → void
    : super core::Object::•()
    ;
}
abstract class _B&Object&A extends core::Object implements self::A<(self::B::Z) → void, core::int> {
  synthetic constructor •() → void
    : super core::Object::•()
    ;
}
class B<Z extends core::Object = dynamic> extends self::_B&Object&A {
  synthetic constructor •() → void
    : super core::Object::•()
    ;
}
static method main() → dynamic {}

Unhandled exception:
Type parameter #lib1::B::Z is not indexed
#0      TypeParameterIndexer.[] (package:kernel/binary/ast_to_binary.dart:2055:28)
#1      BinaryPrinter.visitTypeParameterType (package:kernel/binary/ast_to_binary.dart:1678:38)
#2      TypeParameterType.accept (package:kernel/ast.dart:4839:34)
#3      BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:250:10)
#4      BinaryPrinter.writeNodeList (package:kernel/binary/ast_to_binary.dart:242:7)
#5      BinaryPrinter.visitFunctionType (package:kernel/binary/ast_to_binary.dart:1652:7)
#6      FunctionType.accept (package:kernel/ast.dart:4636:34)
#7      BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:250:10)
#8      BinaryPrinter.writeNodeList (package:kernel/binary/ast_to_binary.dart:242:7)
#9      BinaryPrinter.visitSupertype (package:kernel/binary/ast_to_binary.dart:1641:7)
#10     Supertype.accept (package:kernel/ast.dart:4944:26)
#11     BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:250:10)
#12     BinaryPrinter.writeNodeList (package:kernel/binary/ast_to_binary.dart:242:7)
#13     BinaryPrinter.visitClass (package:kernel/binary/ast_to_binary.dart:768:5)
#14     Class.accept (package:kernel/ast.dart:921:30)
#15     BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:250:10)
#16     BinaryPrinter.writeNodeList (package:kernel/binary/ast_to_binary.dart:242:7)
#17     BinaryPrinter.visitLibrary (package:kernel/binary/ast_to_binary.dart:620:5)
#18     Library.accept (package:kernel/ast.dart:409:30)
#19     BinaryPrinter.writeNode (package:kernel/binary/ast_to_binary.dart:250:10)
#20     List.forEach (dart:core-patch/dart:core/growable_array.dart:278)
#21     BinaryPrinter.writeLibraries (package:kernel/binary/ast_to_binary.dart:445:25)
#22     BinaryPrinter.writeComponentFile (package:kernel/binary/ast_to_binary.dart:328:5)
#23     writeComponentToFile (package:front_end/src/fasta/kernel/utils.dart:45:13)
<asynchronous suspension>
#24     CompileTask.compile (file:///usr/local/google/home/dmitryas/dart/sdk/pkg/front_end/tool/_fasta/entry_points.dart:287:13)
<asynchronous suspension>
#25     compile.<anonymous closure>.<anonymous closure> (file:///usr/local/google/home/dmitryas/dart/sdk/pkg/front_end/tool/_fasta/entry_points.dart:214:25)
<asynchronous suspension>
#26     withGlobalOptions.<anonymous closure> (file:///usr/local/google/home/dmitryas/dart/sdk/pkg/front_end/tool/_fasta/command_line.dart:430:13)
#27     CompilerContext.runWithOptions.<anonymous closure> (package:front_end/src/fasta/compiler_context.dart:131:20)
<asynchronous suspension>
#28     CompilerContext.runInContext.<anonymous closure>.<anonymous closure> (package:front_end/src/fasta/compiler_context.dart:120:46)
#29     new Future.sync (dart:async/future.dart:224)
#30     CompilerContext.runInContext.<anonymous closure> (package:front_end/src/fasta/compiler_context.dart:120:19)
#31     _rootRun (dart:async/zone.dart:1124)
#32     _CustomZone.run (dart:async/zone.dart:1021)
#33     _runZoned (dart:async/zone.dart:1516)
#34     runZoned (dart:async/zone.dart:1463)
#35     CompilerContext.runInContext (package:front_end/src/fasta/compiler_context.dart:119:12)
#36     CompilerContext.runWithOptions (package:front_end/src/fasta/compiler_context.dart:129:10)
#37     withGlobalOptions (file:///usr/local/google/home/dmitryas/dart/sdk/pkg/front_end/tool/_fasta/command_line.dart:423:26)
#38     compile.<anonymous closure> (file:///usr/local/google/home/dmitryas/dart/sdk/pkg/front_end/tool/_fasta/entry_points.dart:207:18)
<asynchronous suspension>
#39     runProtectedFromAbort (file:///usr/local/google/home/dmitryas/dart/sdk/pkg/front_end/tool/_fasta/command_line.dart:478:24)
<asynchronous suspension>
#40     compile (file:///usr/local/google/home/dmitryas/dart/sdk/pkg/front_end/tool/_fasta/entry_points.dart:206:16)
<asynchronous suspension>
#41     compileEntryPoint (file:///usr/local/google/home/dmitryas/dart/sdk/pkg/front_end/tool/_fasta/entry_points.dart:72:11)
<asynchronous suspension>
#42     main (file:///usr/local/google/home/dmitryas/dart/sdk/pkg/front_end/tool/_fasta/compile.dart:7:33)
#43     _startIsolate.<anonymous closure> (dart:isolate-patch/dart:isolate/isolate_patch.dart:287)
#44     _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:171)

Note that the issue isn't present if the subclass of an anonymous mixin application is replaced with a named mixin application. That is, the following program compiles without errors:

class A<X, Y> {}

class B<Z> = Object with A<void Function(Z), int>;

main() {}
@chloestefantsova chloestefantsova added area-front-end Use area-front-end for front end / CFE / kernel format related issues. crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. labels Sep 18, 2018
@kmillikin kmillikin added the P2 A bug or feature request we're likely to work on label Sep 18, 2018
@kmillikin kmillikin added this to the Dart2.1 milestone Sep 18, 2018
@kmillikin
Copy link

It looks like a problem with function types. The test case doesn't need the second type parameter on A, it needs a function type, and it doesn't care if the occurrence of the type parameter is positive or negative.

The code in kernel_library_builder.dart to apply mixins does not handle function types:

      void computeUsedTypeVariables(KernelNamedTypeBuilder type) {
        List<KernelTypeBuilder> typeArguments = type.arguments;
        if (typeArguments != null && typeVariables != null) {
          for (KernelTypeBuilder argument in typeArguments) {
            if (typeVariableNames.contains(argument.name)) {
              usedTypeVariables ??= <String, TypeVariableBuilder>{};
              KernelTypeVariableBuilder freshTypeVariable =
                  (usedTypeVariables[argument.name] ??=
                      addTypeVariable(argument.name, null, charOffset));
              // Notice that [argument] may have been created below as part of
              // [applicationTypeArguments] and have to be rebound now
              // (otherwise it would refer to a type variable in the subclass).
              argument.bind(freshTypeVariable);
            } else {
              if (argument is KernelNamedTypeBuilder) {
                computeUsedTypeVariables(argument);
              }
            }
          }
        }
      }

@kmillikin
Copy link

While this is an issue we need to fix, it's not related to the Dart 2.1 release.

@kmillikin kmillikin modified the milestones: Dart2.1, Dart2.2, PostDart2.1 Oct 9, 2018
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. crash Process exits with SIGSEGV, SIGABRT, etc. An unhandled exception is not a crash. P2 A bug or feature request we're likely to work on
Projects
Dart Front End
Awaiting triage
Development

No branches or pull requests

2 participants