Skip to content

CFE crashes when compiling some code that has Future in it and that requires some inference #34899

@chloestefantsova

Description

@chloestefantsova
Contributor

CFE crashes when it compiles the following code:

class Foo<T> {
  final Future<dynamic> Function() quux;
  T t;

  Foo(this.quux, this.t);

  Future<T> call() => quux().then<T>((_) => t);
}

class Bar {
  Foo<Baz> qux;

  Future<void> quuz() =>
      qux().then((baz) => corge(baz)).then((grault) => garply(grault));

  Grault corge(Baz baz) => null;

  void garply(Grault grault) {}
}

class Baz {}

class Grault {}

The top of the stack trace is the following:

Unhandled exception:                                                                                                                                                                                                                                                            
Crash when compiling file:///tmp/asdf.dart,                                                                                                                                                                                                                                     
at character offset 191:                                                                                                                                                                                                                                                        
dynamic is not a subtype of dart.async::Future in this.{#lib1::Bar::qux}()                                                                                                                                                                                                      
#0      TypeEnvironment.typeError (package:kernel/type_environment.dart:103:7)                                                                                                                                                                                                  
#1      Expression.getStaticTypeAsInstanceOf (package:kernel/ast.dart:2186:11)                                                                                                                                                                                                  
#2      MethodInvocation.getStaticType (package:kernel/ast.dart:2795:35)                                                                                                                                                                                                        
#3      KernelLibraryBuilder.checkBoundsInMethodInvocation (package:front_end/src/fasta/kernel/kernel_library_builder.dart:1831:36)                                                                                                                                             
#4      InferenceVistor.visitMethodInvocationJudgment (file:///usr/local/google/home/dmitryas/dart/sdk/pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart:887:23)                                                                                                        
#5      MethodInvocationJudgment.acceptInference (package:front_end/src/fasta/kernel/kernel_shadow_ast.dart:1129:20)                                                                                                                                                            
#6      ShadowTypeInferrer.inferExpression (package:front_end/src/fasta/kernel/kernel_shadow_ast.dart:1631:18)                                                                                                                                                                  
#7      InferenceVistor.visitReturnJudgment (file:///usr/local/google/home/dmitryas/dart/sdk/pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart:1024:16)                                                                                                                 
#8      ReturnJudgment.acceptInference (package:front_end/src/fasta/kernel/kernel_shadow_ast.dart:1302:20)                                                                                                                                                                      
#9      ShadowTypeInferrer.inferStatement (package:front_end/src/fasta/kernel/kernel_shadow_ast.dart:1679:24)                                                                                                                                                                   
#10     TypeInferrerImpl.inferFunctionBody (package:front_end/src/fasta/type_inference/type_inferrer.dart:1223:5)                                                                                                                                                               
#11     BodyBuilder.finishFunction (package:front_end/src/fasta/kernel/body_builder.dart:724:19)                                                                                                                                                                                
#12     DietListener.listenerFinishFunction (package:front_end/src/fasta/source/diet_listener.dart:795:14)                                                                                                                                                                      
#13     DietListener.buildFunctionBody (package:front_end/src/fasta/source/diet_listener.dart:829:7)                                                                                                                                                                            
#14     DietListener.endMethod (package:front_end/src/fasta/source/diet_listener.dart:578:5)                                                                                                                                                                                    
#15     Parser.parseMethod (package:front_end/src/fasta/parser/parser.dart:3030:14)                                                                                                                                                                                             
#16     Parser.parseClassOrMixinMemberImpl (package:front_end/src/fasta/parser/parser.dart:2895:15)                                                                                                                                                                             
#17     Parser.parseClassOrMixinBody (package:front_end/src/fasta/parser/parser.dart:2700:15)                                                                                                                                                                                   
#18     Parser.parseClass (package:front_end/src/fasta/parser/parser.dart:1710:13)                                                                                                                                                                                              
#19     Parser.parseClassOrNamedMixinApplication (package:front_end/src/fasta/parser/parser.dart:1670:14)                                                                                                                                                                       
#20     Parser.parseTopLevelKeywordDeclaration (package:front_end/src/fasta/parser/parser.dart:565:14)                                                                                                                                                                          
#21     Parser.parseTopLevelDeclarationImpl (package:front_end/src/fasta/parser/parser.dart:457:14)                                                                                                                                                                             
#22     Parser.parseUnit (package:front_end/src/fasta/parser/parser.dart:336:15)                                                                                                                                                                                                
#23     SourceLoader.buildBody (package:front_end/src/fasta/source/source_loader.dart:253:14)
...

Activity

kmillikin

kmillikin commented on Oct 23, 2018

@kmillikin

One underlying problem with the existing implementation in terms of getStaticType is issue #34497.

Basically, for an invocation of a getter whose static type is a callable object (this.qux() in the test case) we generate MethodInvocation(This, 'qux', []) and we should generate MethodInvocation(PropertyGet(This, 'qux'), 'call', []). The former is not what we intend and the Kernel type checker says that it has type dynamic.

(This is inconsistent with what we do for static getters whose static type is a callable object, where we produce MethodInvocation(StaticGet(target), 'call', []); and for invoking a local variable whose static type is a callable object, where we produce MethodInvocation(VariableGet(definition), 'call', []).)

I've started work on #34497.

added
P1A high priority bug; for example, a single project is unusable or has many test failures
type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)
on Oct 23, 2018
added this to the Dart2.1 milestone on Oct 23, 2018
kmillikin

kmillikin commented on Oct 23, 2018

@kmillikin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1A high priority bug; for example, a single project is unusable or has many test failureslegacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @chloestefantsova@kmillikin

      Issue actions

        CFE crashes when compiling some code that has Future in it and that requires some inference · Issue #34899 · dart-lang/sdk