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

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

Closed
chloestefantsova opened this issue Oct 23, 2018 · 2 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

Comments

@chloestefantsova
Copy link
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)
...
@chloestefantsova chloestefantsova self-assigned this Oct 23, 2018
dart-bot pushed a commit that referenced this issue Oct 23, 2018
Bug: http://dartbug.com/34899
Change-Id: Ia7d9c0c9be711e3f9f0e07552222f1b28a140ec1
Reviewed-on: https://dart-review.googlesource.com/c/81240
Reviewed-by: Peter von der Ahé <ahe@google.com>
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
@kmillikin
Copy link

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.

@kmillikin kmillikin added area-front-end Use area-front-end for front end / CFE / kernel format related issues. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 23, 2018
@kmillikin kmillikin added this to the Dart2.1 milestone Oct 23, 2018
@kmillikin
Copy link

Work in progress on a fix is in https://dart-review.googlesource.com/c/sdk/+/81266

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. P1 A high priority bug; for example, a single project is unusable or has many test failures type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants