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

[dev_compiler] Web: Unsupported operation: Undetermined nullability #52726

Closed
llfbandit opened this issue Jun 18, 2023 · 14 comments
Closed

[dev_compiler] Web: Unsupported operation: Undetermined nullability #52726

llfbandit opened this issue Jun 18, 2023 · 14 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. cfe-encodings Encoding related CFE issues. web-dev-compiler

Comments

@llfbandit
Copy link

Context: Flutter web plugin implementation interoperating with JS.

This exception is only thrown in debug mode, release mode is OK.

Package issue reference

  • Dart SDK Version 3.0.5 shipped with Flutter 3.10.5
Here's the stack trace
Unhandled exception:
Unsupported operation: Undetermined nullability. Encountered while compiling file:///......./Pub/Cache/hosted/pub.dev/typings-0.0.1+1/lib/src/d/core/lib_es2015_collection_d.dart, which contains the type: InterfaceType(Object%).
lib_es2015_collection_d.dart:1
#0      ProgramCompiler._typeCompilationError (package:dev_compiler/src/kernel/compiler.dart:3355:7)
#1      ProgramCompiler._undeterminedNullabilityError (package:dev_compiler/src/kernel/compiler.dart:3352:7)
#2      ProgramCompiler._emitInterfaceType (package:dev_compiler/src/kernel/compiler.dart:3277:7)
#3      ProgramCompiler.visitInterfaceType (package:dev_compiler/src/kernel/compiler.dart:3191:7)
#4      InterfaceType.accept (package:kernel/ast.dart:12100:42)
#5      MappedListIterable.elementAt (dart:_internal/iterable.dart:415:31)
#6      MappedListIterable.elementAt (dart:_internal/iterable.dart:415:40)
#7      ListIterator.moveNext (dart:_internal/iterable.dart:344:26)
#8      InstantiatorGeneratorVisitor.splayNodes (package:dev_compiler/src/js_ast/template.dart:224:23)
#9      InstantiatorGeneratorVisitor.handleCallOrNew.<anonymous closure> (package:dev_compiler/src/js_ast/template.dart:604:22)
#10     Template.instantiate (package:dev_compiler/src/js_ast/template.dart:118:26)
#11     JsBuilder.call (package:dev_compiler/src/js_ast/builder.dart:212:21)
#12     ProgramCompiler._emitGenericClassType (package:dev_compiler/src/kernel/compiler.dart:3393:15)
#13     ProgramCompiler._emitInterfaceType (package:dev_compiler/src/kernel/compiler.dart:3256:17)
#14     ProgramCompiler.visitInterfaceType (package:dev_compiler/src/kernel/compiler.dart:3191:7)

#15     InterfaceType.accept (package:kernel/ast.dart:12100:42)
#16     ProgramCompiler._emitType (package:dev_compiler/src/kernel/compiler.dart:3076:60)
#17     ProgramCompiler._emitArgumentList (package:dev_compiler/src/kernel/compiler.dart:6223:41)
#18     ProgramCompiler._emitMethodCall (package:dev_compiler/src/kernel/compiler.dart:5326:16)
#19     ProgramCompiler.visitInstanceInvocation (package:dev_compiler/src/kernel/compiler.dart:5240:12)
#20     InstanceInvocation.accept (package:kernel/ast.dart:6128:44)
#21     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:4232:20)
#22     ProgramCompiler._emitMethodCall (package:dev_compiler/src/kernel/compiler.dart:5325:22)
#23     ProgramCompiler.visitInstanceInvocation (package:dev_compiler/src/kernel/compiler.dart:5240:12)
#24     InstanceInvocation.accept (package:kernel/ast.dart:6128:44)
#25     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:4232:20)
#26     ProgramCompiler.visitConditionalExpression (package:dev_compiler/src/kernel/compiler.dart:6598:21)
#27     ConditionalExpression.accept (package:kernel/ast.dart:7420:44)
#28     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:4232:20)
#29     ProgramCompiler.visitLet (package:dev_compiler/src/kernel/compiler.dart:6996:16)
#30     Let.accept (package:kernel/ast.dart:9277:44)
#31     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:4232:20)
#32     ProgramCompiler.visitLet (package:dev_compiler/src/kernel/compiler.dart:6995:16)
#33     Let.accept (package:kernel/ast.dart:9277:44)
#34     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:4232:20)
#35     MappedListIterable.elementAt (dart:_internal/iterable.dart:415:31)
#36     ListIterator.moveNext (dart:_internal/iterable.dart:344:26)

#37     new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#38     new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#39     new List.of (dart:core-patch/array_patch.dart:47:28)
#40     ListIterable.toList (dart:_internal/iterable.dart:214:7)
#41     ProgramCompiler._visitExpressionList (package:dev_compiler/src/kernel/compiler.dart:4195:40)
#42     ProgramCompiler.visitListLiteral (package:dev_compiler/src/kernel/compiler.dart:6833:20)
#43     ListLiteral.accept (package:kernel/ast.dart:8700:44)
#44     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:4232:20)
#45     ProgramCompiler._emitArgumentList (package:dev_compiler/src/kernel/compiler.dart:6232:11)

#46     ProgramCompiler.visitStaticInvocation (package:dev_compiler/src/kernel/compiler.dart:6146:16)
#47     StaticInvocation.accept (package:kernel/ast.dart:7029:44)
#48     ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:4232:20)
#49     ProgramCompiler.visitReturnStatement (package:dev_compiler/src/kernel/compiler.dart:4794:45)
#50     ReturnStatement.accept (package:kernel/ast.dart:10786:43)
#51     ProgramCompiler._visitStatement (package:dev_compiler/src/kernel/compiler.dart:4141:20)

#52     ProgramCompiler._emitFunctionScopedBody (package:dev_compiler/src/kernel/compiler.dart:4174:18)
#53     ProgramCompiler._emitSyncFunctionBody.<anonymous closure> (package:dev_compiler/src/kernel/compiler.dart:3909:17)
#54     ProgramCompiler._withLetScope (package:dev_compiler/src/kernel/compiler.dart:2593:25)

#55     ProgramCompiler._withCurrentFunction (package:dev_compiler/src/kernel/compiler.dart:3943:18)
#56     ProgramCompiler._emitSyncFunctionBody (package:dev_compiler/src/kernel/compiler.dart:3905:17)

#57     ProgramCompiler._emitFactoryConstructor (package:dev_compiler/src/kernel/compiler.dart:2310:18)
#58     ProgramCompiler._emitJSInteropClassNonExternalMembers (package:dev_compiler/src/kernel/compiler.dart:919:23)

#59     ProgramCompiler._emitClass (package:dev_compiler/src/kernel/compiler.dart:734:31)
#60     List.forEach (dart:core-patch/growable_array.dart:416:8)
#61     ProgramCompiler._emitLibrary (package:dev_compiler/src/kernel/compiler.dart:670:23)
#62     List.forEach (dart:core-patch/growable_array.dart:416:8)

#63     ProgramCompiler.emitModule (package:dev_compiler/src/kernel/compiler.dart:479:15)
#64     IncrementalJavaScriptBundler.compile (package:frontend_server/src/javascript_bundle.dart:217:33)
#65     FrontendCompiler.writeJavaScriptBundle (package:frontend_server/frontend_server.dart:778:46)
<asynchronous suspension>
#66     FrontendCompiler.compile (package:frontend_server/frontend_server.dart:641:9)
<asynchronous suspension>

#67     listenAndCompile.<anonymous closure> (package:frontend_server/frontend_server.dart:1308:11)
<asynchronous suspension>

the Dart compiler exited unexpectedly.
Failed to compile application.
@lrhn lrhn added the area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. label Jun 18, 2023
@srujzs
Copy link
Contributor

srujzs commented Jun 20, 2023

Thanks for filing! Can you share with us a minimal repro of this issue?

cc @nshahan

@llfbandit
Copy link
Author

llfbandit commented Jun 20, 2023

Here's a reproducer. this is Flutter app.
This is purely default app with typings package dependency added and an attachment to foo method call to avoid tree shake on unused package.

dev_compiler_issue.zip

@jodinathan
Copy link

is there anything I could change in Typings to fix this @srujzs ?

@srujzs
Copy link
Contributor

srujzs commented Aug 17, 2023

There's likely some type here that the CFE is unable to determine the nullability of correctly, which throws in DDC, so yes, but I still need to figure out what the offending code is here. I'm trying to run typings but keep coming across issues when trying to do with build_runner e.g.

log
srujzs-macbookpro:typingsissue srujzs$ dart run build_runner build
Building package executable... (6.6s)
Built build_runner:build_runner.
[INFO] Generating build script completed, took 412ms
[WARNING] ../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/project.dart:61:1: Error: This requires the experimental 'inline-class' language feature to be enabled.
Try passing the '--enable-experiment=inline-class' command line option.
inline class ExternalInteropModule {
^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/project.dart:77:1: Error: This requires the experimental 'inline-class' language feature to be enabled.
Try passing the '--enable-experiment=inline-class' command line option.
inline class ExternalInteropProject {
^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/ast/library.dart:149:19: Error: The setter 'external' isn't defined for the class 'FieldBuilder'.
 - 'FieldBuilder' is from 'package:code_builder/src/specs/field.dart' ('../../.pub-cache/hosted/pub.dev/code_builder-4.5.0/lib/src/specs/field.dart').
Try correcting the name to the name of an existing setter, or defining a setter or field named 'external'.
                ..external = true
                  ^^^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/ast/library.dart:171:23: Error: The setter 'external' isn't defined for the class 'FieldBuilder'.
 - 'FieldBuilder' is from 'package:code_builder/src/specs/field.dart' ('../../.pub-cache/hosted/pub.dev/code_builder-4.5.0/lib/src/specs/field.dart').
Try correcting the name to the name of an existing setter, or defining a setter or field named 'external'.
                    ..external = true
                      ^^^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/ast/property.dart:61:13: Error: The setter 'external' isn't defined for the class 'FieldBuilder'.
 - 'FieldBuilder' is from 'package:code_builder/src/specs/field.dart' ('../../.pub-cache/hosted/pub.dev/code_builder-4.5.0/lib/src/specs/field.dart').
Try correcting the name to the name of an existing setter, or defining a setter or field named 'external'.
          ..external = true;
            ^^^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/metadata/struct.dart:4:1: Error: This requires the experimental 'inline-class' language feature to be enabled.
Try passing the '--enable-experiment=inline-class' command line option.
inline class MetadataCtor {
^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/metadata/struct.dart:10:1: Error: This requires the experimental 'inline-class' language feature to be enabled.
Try passing the '--enable-experiment=inline-class' command line option.
inline class MetadataIndex {
^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/metadata/struct.dart:22:1: Error: This requires the experimental 'inline-class' language feature to be enabled.
Try passing the '--enable-experiment=inline-class' command line option.
inline class MetadataCall {
^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/metadata/struct.dart:28:1: Error: This requires the experimental 'inline-class' language feature to be enabled.
Try passing the '--enable-experiment=inline-class' command line option.
inline class MetadataStruct {
^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/metadata/struct.dart:80:1: Error: This requires the experimental 'inline-class' language feature to be enabled.
Try passing the '--enable-experiment=inline-class' command line option.
inline class MetadataTypeRef {
^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/metadata/struct.dart:88:1: Error: This requires the experimental 'inline-class' language feature to be enabled.
Try passing the '--enable-experiment=inline-class' command line option.
inline class MetadataStructMember {
^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/ast/method.dart:266:19: Error: The getter 'namedParameters' isn't defined for the class 'RecordTypeBuilder'.
 - 'RecordTypeBuilder' is from 'package:code_builder/src/specs/type_record.dart' ('../../.pub-cache/hosted/pub.dev/code_builder-4.5.0/lib/src/specs/type_record.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'namedParameters'.
                b.namedParameters['\$${index + start}'] = element.express;
                  ^^^^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/ast/method.dart:266:67: Error: The getter 'express' isn't defined for the class 'Method'.
 - 'Method' is from 'package:code_builder/src/specs/method.dart' ('../../.pub-cache/hosted/pub.dev/code_builder-4.5.0/lib/src/specs/method.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'express'.
                b.namedParameters['\$${index + start}'] = element.express;
                                                                  ^^^^^^^
../../.pub-cache/hosted/pub.dev/ts2dart-0.0.2/lib/src/ast/types/tuple.dart:41:11: Error: The getter 'parameters' isn't defined for the class 'RecordTypeBuilder'.
 - 'RecordTypeBuilder' is from 'package:code_builder/src/specs/type_record.dart' ('../../.pub-cache/hosted/pub.dev/code_builder-4.5.0/lib/src/specs/type_record.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'parameters'.
        b.parameters.add(type.ref());
          ^^^^^^^^^^
[INFO] Precompiling build script... completed, took 1.1s
[SEVERE] Failed to precompile build script .dart_tool/build/entrypoint/build.dart.

Any idea where I'm going wrong in trying to use the package?

@jodinathan
Copy link

I use inline classes in ts2dart I guess it changed to extension types or something like that.
Try with SDK 3.0.7

@srujzs
Copy link
Contributor

srujzs commented Aug 17, 2023

Hmm I don't think the migration to extension types is the issue, we haven't removed support for the inline class syntax yet either. Trying it with SDK 3.0.7 still produces the same error for me.

Are you running this with something besides build_runner? I'm avoiding using Flutter to do this as it adds some extra step to use a custom Dart SDK and debug.

@jodinathan
Copy link

You need to clean things up when changing the SDK, please try

rm -Rf .dart_tool
dart pub get
./run.sh

@srujzs
Copy link
Contributor

srujzs commented Aug 18, 2023

Couldn't get that to work but ended up debugging using a local Flutter engine. The failure is at: https://github.com/jodinathan/typings/blob/e8e231c7905af52bc24538fe4ea17486e81cbc4d/typings/lib/src/d/core/lib.es2015.collection.d.dart#L265

A simple repro for the undetermined nullability error:

class WeakMap<K extends Object, V> {
  WeakMap(List<(K, V)> entries) {
    entries.map((i) => [i.$1, i.$2]);
  }
}

void main() {}

The fix seems to be just add an explicit <Object?> to the list within the map function (at least in the simple repro). Weirdly enough, removing the extends Object also fixes this.

cc @johnniwinther

@nshahan
Copy link
Contributor

nshahan commented Aug 18, 2023

@srujzs You are a hero for finding the offending line of code! Thank you!

It looks like the issue arrises from combining values with the types K extends Object and V into the same list. The inferred type argument of the list creates the intersection Object% (undetermined nullability). Should it be inferred as Object? instead?

You can trigger the same issue with an even smaller repro:

fn<T extends Object, S>(T t, S s) => [t, s];

void main() {}

cc @stereotype441

@nshahan nshahan added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Sep 11, 2023
@jodinathan
Copy link

will this be fixed in 3.2?

@nshahan
Copy link
Contributor

nshahan commented Nov 7, 2023

@chloestefantsova Are there still plans to resolve this in the CFE?

@chloestefantsova
Copy link
Contributor

@nshahan Sorry for the very late reply. Yes, I'm working on a fix at https://dart-review.googlesource.com/c/sdk/+/334441.

@jodinathan
Copy link

can this please be fixed in 3.2, there are many, many complaints that they can't use Typings because of this bug

@chloestefantsova
Copy link
Contributor

can this please be fixed in 3.2, there are many, many complaints that they can't use Typings because of this bug

I filed an issue to speed up the inclusion of the fix. However, I can't provide any estimates for when it actually will be included.

copybara-service bot pushed a commit that referenced this issue Nov 24, 2023
Closes #52726

Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/334441
Cherry-pick-request: #53999
Fixes: #53999
Change-Id: I365c548c3a3a203797cbd73ec7798ff29dfd3f98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333825
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
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. area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. cfe-encodings Encoding related CFE issues. web-dev-compiler
Projects
None yet
Development

No branches or pull requests

8 participants
@chloestefantsova @nshahan @llfbandit @lrhn @jodinathan @johnniwinther @srujzs and others