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

Front end crash when trying to infer a type parameter based on a generic function type #38973

Open
stereotype441 opened this issue Oct 18, 2019 · 0 comments
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.

Comments

@stereotype441
Copy link
Member

Attempting to execute the following program with the Dart VM:

T f<T>() => throw 'foo';
U g<U>(void Function<V extends U>() x) => throw 'bar';
main() {
  var x = g(f());
}

produces a crash with the following stack trace:

NoSuchMethodError: The method 'accept' was called on null.
Receiver: null
Tried calling: accept<bool>(Instance of '_IsKnownVisitor')
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      isKnown (package:front_end/src/fasta/type_inference/type_schema.dart:23:41)
#2      TypeSchemaEnvironment.solveTypeConstraint (package:front_end/src/fasta/type_inference/type_schema_environment.dart:350:9)
#3      TypeSchemaEnvironment._inferTypeParameterFromAll (package:front_end/src/fasta/type_inference/type_schema_environment.dart:385:12)
#4      TypeSchemaEnvironment.inferTypeFromConstraints (package:front_end/src/fasta/type_inference/type_schema_environment.dart:247:28)
#5      TypeSchemaEnvironment.inferGenericFunctionOrType (package:front_end/src/fasta/type_inference/type_schema_environment.dart:190:5)
#6      TypeInferrerImpl._inferInvocation (package:front_end/src/fasta/type_inference/type_inferrer.dart:1750:29)
#7      TypeInferrerImpl.inferInvocation (package:front_end/src/fasta/type_inference/type_inferrer.dart:1511:12)
#8      InferenceVisitor.visitStaticInvocation (package:front_end/src/fasta/kernel/inference_visitor.dart:4391:38)
#9      StaticInvocation.accept1 (package:kernel/ast.dart:3365:9)
#10     ShadowTypeInferrer.inferExpression (package:front_end/src/fasta/kernel/kernel_shadow_ast.dart:871:27)
#11     InferenceVisitor.visitVariableDeclaration (package:front_end/src/fasta/kernel/inference_visitor.dart:4604:36)
#12     VariableDeclaration.accept (package:kernel/ast.dart:5201:43)
#13     ShadowTypeInferrer.inferStatement (package:front_end/src/fasta/kernel/kernel_shadow_ast.dart:906:17)
#14     InferenceVisitor.visitBlock (package:front_end/src/fasta/kernel/inference_visitor.dart:276:16)
#15     Block.accept (package:kernel/ast.dart:4453:43)
#16     ShadowTypeInferrer.inferStatement (package:front_end/src/fasta/kernel/kernel_shadow_ast.dart:906:17)
#17     TypeInferrerImpl.inferFunctionBody (package:front_end/src/fasta/type_inference/type_inferrer.dart:1482:5)
#18     BodyBuilder.finishFunction (package:front_end/src/fasta/kernel/body_builder.dart:848:19)
#19     DietListener.listenerFinishFunction (package:front_end/src/fasta/source/diet_listener.dart:895:14)
#20     DietListener.buildFunctionBody (package:front_end/src/fasta/source/diet_listener.dart:928:7)
#21     DietListener.endTopLevelMethod (package:front_end/src/fasta/source/diet_listener.dart:342:5)
#22     Parser.parseTopLevelMethod (package:front_end/src/fasta/parser/parser.dart:2499:14)
#23     Parser.parseTopLevelMemberImpl (package:front_end/src/fasta/parser/parser.dart:2353:14)
#24     Parser.parseTopLevelDeclarationImpl (package:front_end/src/fasta/parser/parser.dart:493:14)
#25     Parser.parseUnit (package:front_end/src/fasta/parser/parser.dart:350:15)
#26     SourceLoader.buildBody (package:front_end/src/fasta/source/source_loader.dart:298:14)
<asynchronous suspension>
#27     Loader.buildBodies (package:front_end/src/fasta/loader.dart:243:15)
<asynchronous suspension>
...

Attempting to analyze the same program with the analyzer produces the following error message at the site of the call to f:

error • Couldn't infer type parameter 'T'. Inferred candidate type void Function<V extends ?>() has type parameters [V extends ?], but a function with type parameters cannot be used as a type argument.
@stereotype441 stereotype441 added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Oct 18, 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

1 participant