sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Unsupported operation: Unsupported type UnknownType(?) (UnknownType.

Open jodinathan opened this issue 3 years ago • 5 comments

after upgrading to 2.18 this error started happening in our server app without any hint of what is going on

dart run --verbosity=all --observe bin/dev.dart
The Dart VM service is listening on http://127.0.0.1:8181/ojtWDog4N1E=/
The Dart DevTools debugger and profiler is available at: http://127.0.0.1:8181/ojtWDog4N1E=/devtools/#/?uri=ws%3A%2F%2F127.0.0.1%3A8181%2FojtWDog4N1E%3D%2Fws
Crash when compiling null,
at character offset null:
Unsupported operation: Unsupported type UnknownType(?) (UnknownType.
#0      _AllFreeTypeVariablesVisitor.defaultDartType (package:kernel/type_algebra.dart:315:5)
#1      UnknownType.accept (package:front_end/src/fasta/type_inference/type_schema.dart:83:14)
#2      _AllFreeTypeVariablesVisitor.visit (package:kernel/type_algebra.dart:311:37)
#3      allFreeTypeVariables (package:kernel/type_algebra.dart:18:11)
#4      _FunctionLiteralDependencies.typeVarsFreeInParamReturns (package:front_end/src/fasta/type_inference/type_inferrer.dart:6010:14)
#5      new FunctionLiteralDependencies (package:_fe_analyzer_shared/src/deferred_function_literal_heuristic.dart:38:30)
#6      new _FunctionLiteralDependencies (package:front_end/src/fasta/type_inference/type_inferrer.dart:5982:9)
#7      InferenceVisitorBase._inferInvocation (package:front_end/src/fasta/type_inference/type_inferrer.dart:2545:50)
#8      InferenceVisitorBase.inferInvocation (package:front_end/src/fasta/type_inference/type_inferrer.dart:2188:12)
#9      InferenceVisitorImpl.visitTypeAliasedConstructorInvocation (package:front_end/src/fasta/type_inference/inference_visitor.dart:1185:40)
#10     TypeAliasedConstructorInvocation.acceptInference (package:front_end/src/fasta/kernel/internal_ast.dart:827:20)
#11     InferenceVisitorImpl._inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:126:27)
#12     InferenceVisitorImpl.inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:165:40)
#13     TypeInferrerImpl.inferImplicitFieldType (package:front_end/src/fasta/type_inference/type_inferrer.dart:289:48)
#14     _ImplicitFieldTypeRoot.computeType (package:front_end/src/fasta/kernel/implicit_field_type.dart:139:24)
#15     SourceFieldBuilder.inferType (package:front_end/src/fasta/source/source_field_builder.dart:474:47)
#16     SourceFieldBuilder.inferTypes (package:front_end/src/fasta/source/source_field_builder.dart:464:5)
#17     InferableTypeBuilder.inferType (package:front_end/src/fasta/builder/omitted_type_builder.dart:149:19)
#18     SourceLoader.performTopLevelInference (package:front_end/src/fasta/source/source_loader.dart:2358:19)
#19     KernelTarget.buildOutlines.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:532:14)
<asynchronous suspension>
#20     withCrashReporting (package:front_end/src/fasta/crash.dart:122:12)
<asynchronous suspension>
#21     IncrementalCompiler.computeDelta.<anonymous closure> (package:front_end/src/fasta/incremental_compiler.dart:407:33)
<asynchronous suspension>
#22     IncrementalCompiler.compile (package:vm/incremental_compiler.dart:68:50)
<asynchronous suspension>
#23     IncrementalCompilerWrapper.compileInternal (file:///opt/s/w/ir/x/w/sdk/pkg/vm/bin/kernel_service.dart:345:28)
<asynchronous suspension>
#24     Compiler.compile.<anonymous closure> (file:///opt/s/w/ir/x/w/sdk/pkg/vm/bin/kernel_service.dart:221:45)
<asynchronous suspension>
#25     _processLoadRequest (file:///opt/s/w/ir/x/w/sdk/pkg/vm/bin/kernel_service.dart:914:37)
<asynchronous suspension>


#0      _AllFreeTypeVariablesVisitor.defaultDartType (package:kernel/type_algebra.dart:315:5)
#1      UnknownType.accept (package:front_end/src/fasta/type_inference/type_schema.dart:83:14)
#2      _AllFreeTypeVariablesVisitor.visit (package:kernel/type_algebra.dart:311:37)
#3      allFreeTypeVariables (package:kernel/type_algebra.dart:18:11)
#4      _FunctionLiteralDependencies.typeVarsFreeInParamReturns (package:front_end/src/fasta/type_inference/type_inferrer.dart:6010:14)
#5      new FunctionLiteralDependencies (package:_fe_analyzer_shared/src/deferred_function_literal_heuristic.dart:38:30)
#6      new _FunctionLiteralDependencies (package:front_end/src/fasta/type_inference/type_inferrer.dart:5982:9)
#7      InferenceVisitorBase._inferInvocation (package:front_end/src/fasta/type_inference/type_inferrer.dart:2545:50)
#8      InferenceVisitorBase.inferInvocation (package:front_end/src/fasta/type_inference/type_inferrer.dart:2188:12)
#9      InferenceVisitorImpl.visitTypeAliasedConstructorInvocation (package:front_end/src/fasta/type_inference/inference_visitor.dart:1185:40)
#10     TypeAliasedConstructorInvocation.acceptInference (package:front_end/src/fasta/kernel/internal_ast.dart:827:20)
#11     InferenceVisitorImpl._inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:126:27)
#12     InferenceVisitorImpl.inferExpression (package:front_end/src/fasta/type_inference/inference_visitor.dart:165:40)
#13     TypeInferrerImpl.inferImplicitFieldType (package:front_end/src/fasta/type_inference/type_inferrer.dart:289:48)
#14     _ImplicitFieldTypeRoot.computeType (package:front_end/src/fasta/kernel/implicit_field_type.dart:139:24)
#15     SourceFieldBuilder.inferType (package:front_end/src/fasta/source/source_field_builder.dart:474:47)
#16     SourceFieldBuilder.inferTypes (package:front_end/src/fasta/source/source_field_builder.dart:464:5)
#17     InferableTypeBuilder.inferType (package:front_end/src/fasta/builder/omitted_type_builder.dart:149:19)
#18     SourceLoader.performTopLevelInference (package:front_end/src/fasta/source/source_loader.dart:2358:19)
#19     KernelTarget.buildOutlines.<anonymous closure> (package:front_end/src/fasta/kernel/kernel_target.dart:532:14)
<asynchronous suspension>
#20     withCrashReporting (package:front_end/src/fasta/crash.dart:122:12)
<asynchronous suspension>
#21     IncrementalCompiler.computeDelta.<anonymous closure> (package:front_end/src/fasta/incremental_compiler.dart:407:33)
<asynchronous suspension>
#22     IncrementalCompiler.compile (package:vm/incremental_compiler.dart:68:50)
<asynchronous suspension>
#23     IncrementalCompilerWrapper.compileInternal (file:///opt/s/w/ir/x/w/sdk/pkg/vm/bin/kernel_service.dart:345:28)
<asynchronous suspension>
#24     Compiler.compile.<anonymous closure> (file:///opt/s/w/ir/x/w/sdk/pkg/vm/bin/kernel_service.dart:221:45)
<asynchronous suspension>
#25     _processLoadRequest (file:///opt/s/w/ir/x/w/sdk/pkg/vm/bin/kernel_service.dart:914:37)
<asynchronous suspension>

jodinathan avatar Sep 17 '22 13:09 jodinathan

Given the stack trace the error occurs when trying to infer the type for a field initialized to an invocation of a constructor through a typedef using a function expression as argument. Something like field in this:

typedef A<T> = B<T, int>;
class B<X, Y> {
  B(X f);
}
var field = A((a, b) => a);

The example doesn't reproduce the crash, so if you can find a repro from this description it'll be appreciated. Note that you can work around the problem by typing the declaration explicitly. For instance

A<dynamic Function(dynamic, dynamic>, int> field = 
    A<dynamic Function(dynamic, dynamic), int>((dynamic a, dynamic b) => a);

johnniwinther avatar Sep 19 '22 10:09 johnniwinther

is it possible for the error to show what file and line number is the culprit?

jodinathan avatar Sep 19 '22 11:09 jodinathan

It is trying to (see the Crash when compiling null part of the message) but since this part of the compilation (the top level inference) is following the code usage and therefore can jump from file to file, this information is not tracked here. We should work on that, though.

johnniwinther avatar Sep 19 '22 11:09 johnniwinther

kinda impossible to find the source of the problem, our project is really big.

shouldn't the analysis server warn about this?

jodinathan avatar Sep 19 '22 12:09 jodinathan

The problem is internal to the front end so there is nothing wrong with your code, just our implementation. What happens is that an internal type, UnknownType, used for type inference, occurs at a spot where it shouldn't.

I can make a work-around fix, but also want to know how this can happen in the first place.

johnniwinther avatar Sep 19 '22 13:09 johnniwinther

While not solving the immediate problem, I've updated the front end to support "current uri" during top level inference. With this change, we can at least see which file it was working on when it crashed: https://dart.googlesource.com/sdk/+/d43aa20afaa23d40e14c077a9344f2eb71320a4e

johnniwinther avatar Sep 23 '22 14:09 johnniwinther

I found a repro:

typedef A<T> = C<T, int>;
class B<X, Y> {
  X x;
  B(this.x);
}
mixin Mixin {}
class C<X, Y> = B<X, Y> with Mixin;
var field = A((a, b) => 42);

johnniwinther avatar Sep 23 '22 15:09 johnniwinther

great!

While not solving the immediate problem, I've updated the front end to support "current uri" during top level inference. With this change, we can at least see which file it was working on when it crashed

Is it published at the main branch?
I am curious to see where in our code the error occur

jodinathan avatar Sep 23 '22 17:09 jodinathan

So, with the repro, I was able to fix the underlying bug.

As for when it (and the improvement to the crash message) lands, it'll be a while, depending on which release channel follow. The dev channel is weekly, the beta channel is monthly and the stable channel is quarterly.

@jodinathan Are you blocked on this issue?

johnniwinther avatar Sep 26 '22 10:09 johnniwinther

@jodinathan Are you blocked on this issue?

no. We aways try to use the latest SDK but we are not blocked. Thanks

jodinathan avatar Sep 26 '22 12:09 jodinathan