dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.11k stars 1.56k forks source link

dart/runtime/vm/kernel_binary.h: 435: error: Legacy nullability is not supported. #56548

Open LefebvreIlyas opened 1 month ago

LefebvreIlyas commented 1 month ago

Hello

After updating to Flutter 3.24.0, which uses Dart 3.5, I now get the error “Legacy nullability is not supported. The error is also present with Flutter 3.25.0-1.0.pre.84 and Dart 3.6.0-167.0.dev.

I'm creating the issue here because I think it's really language specific.

I don't think it's due to a bug in the SDK or Flutter tooling but rather due to a dependency of a package I use in all my projects, because without it, the code compiles. I can't find the problem. I've tried deleting some dependencies and trying to compile, sometimes it ends up working and sometimes it doesn't (with dependencies for which it worked in previous tests and vice versa). All dependencies are marked Dart 3 compatible and support null safety.

I've also been unable to produce a minimal example reproducing the error. By creating an empty project and adding all the dependencies, the project compiles, I don't know if it's because the problematic code/package is removed by tree shaking.

What exactly is the meaning of this error and what approach should be taken when it occurs?

The error

[  +11 ms] √ Built build\windows\x64\runner\Debug\application.exe
[+3061 ms] VM Service URL on device: http://127.0.0.1:56742/ZEzGNwrISD8=/
[   +1 ms] Caching compiled dill
[  +41 ms] Connecting to service protocol: http://127.0.0.1:56742/ZEzGNwrISD8=/
[  +54 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:56742/ZEzGNwrISD8=/.
[   +3 ms] ../../../flutter/third_party/dart/runtime\vm/kernel_binary.h: 435: error: Legacy nullability is not supported.
[        ] version=3.5.1 (stable) (Tue Aug 13 21:02:17 2024 +0000) on "windows_x64"
[        ] pid=8600, thread=13368, isolate_group=main(00000177FE22D0B0), isolate=(nil)(0000000000000000)
[        ] os=windows, arch=x64, comp=no, sim=no
[        ] isolate_instructions=7fff872fc640, vm_instructions=7fff872fc650
[        ] fp=50d0ffdbe8, sp=50d0ffdbe8, pc=7fff870ebad2
[   +6 ms]   pc 0x00007fff870ebad2 fp 0x00000050d0ffdbe8 InternalFlutterGpu_Texture_AsImage+0x12bc76
[        ] -- End of DumpStackTrace
[ +697 ms] Warning: Failed to start DDS: Failed to start Dart Development Service
[        ] Fail to connect to service protocol: http://127.0.0.1:56742/ZEzGNwrISD8=/: DartDevelopmentServiceException: Failed to start Dart Development Service
[        ] Error connecting to the service protocol: failed to connect to http://127.0.0.1:56742/ZEzGNwrISD8=/
dart-github-bot commented 1 month ago

Summary: The user is experiencing an error "Legacy nullability is not supported" after updating to Flutter 3.24.0, which uses Dart 3.5. The error occurs during compilation and seems to be related to a dependency in their project, but they are unable to pinpoint the specific package causing the issue.

mraleph commented 1 month ago

It means there is a type in the program which has a legacy nullability for some reason. You could try the following:

  1. Clean your build folders (flutter clean)
  2. Reproduce the problem.
  3. Find a *.dill in the build folder: usually there will be something like ./build/cache.dill.track.dill.
  4. Download dump.dill tool dump.dill.zip (this is produced by doing dart compile kernel pkg/kernel/bin/dump.dart in SDK sources if you want to make it yourself).
  5. Execute dart dump.dill $path-to-dill-from-build-folder dill.txt
  6. Open dill.txt and search there for occurrences of * next to the type name (e.g. something like \w+\* as a regexp should find it).

If you found anything on step 6 then please post the code around it - that should indicate what the problem is.

LefebvreIlyas commented 1 month ago

Hello @mraleph

When I try step 5, I get this error

The command

C:\...\fvm\default\bin\dart "C:\...\Downloads\dump.dill\dump.dill" 05904be6cbf0a7e2303c95156f2c6ef1.cache.dill.track.dill dill.txt

The error

Unhandled exception:
Reference to dart:core::StackTrace::@factories::fromString is not bound to an AST node. A procedure was expected
#0      Reference.asProcedure (package:kernel/canonical_name.dart:543:7)
#1      RedirectingFactoryTearOffConstant.target (package:kernel/ast.dart:14260:43)
#2      RedirectingFactoryTearOffConstant.visitChildren (package:kernel/ast.dart:14267:5)
#3      ConstantNamer.getName (package:kernel/text/ast_to_text.dart:61:18)
#4      NameSystem.nameConstant (package:kernel/text/ast_to_text.dart:159:51)
#5      Printer.writeConstantReference (package:kernel/text/ast_to_text.dart:2757:30)
#6      Printer.visitConstantExpression (package:kernel/text/ast_to_text.dart:2765:5)
#7      ConstantExpression.accept (package:kernel/ast.dart:8636:44)
#8      Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#9      Printer.writeList (package:kernel/text/ast_to_text.dart:913:15)
#10     Printer.visitArguments (package:kernel/text/ast_to_text.dart:2487:5)
#11     Arguments.accept (package:kernel/ast.dart:5394:38)
#12     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#13     Printer.visitStaticInvocation (package:kernel/text/ast_to_text.dart:1587:5)
#14     StaticInvocation.accept (package:kernel/ast.dart:6582:44)
#15     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#16     Printer.writeExpression (package:kernel/text/ast_to_text.dart:1027:5)
#17     Printer.visitConditionalExpression (package:kernel/text/ast_to_text.dart:1627:5)
#18     ConditionalExpression.accept (package:kernel/ast.dart:6938:44)
#19     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#20     Printer.writeExpression (package:kernel/text/ast_to_text.dart:1027:5)
#21     Printer.visitLet (package:kernel/text/ast_to_text.dart:1899:5)
#22     Let.accept (package:kernel/ast.dart:8706:44)
#23     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#24     Printer.writeList (package:kernel/text/ast_to_text.dart:913:15)
#25     Printer.visitArguments (package:kernel/text/ast_to_text.dart:2487:5)
#26     Arguments.accept (package:kernel/ast.dart:5394:38)
#27     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#28     Printer.visitFunctionInvocation (package:kernel/text/ast_to_text.dart:1483:5)
#29     FunctionInvocation.accept (package:kernel/ast.dart:6069:44)
#30     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#31     Printer.writeExpression (package:kernel/text/ast_to_text.dart:1027:5)
#32     Printer.visitExpressionStatement (package:kernel/text/ast_to_text.dart:2168:5)
#33     ExpressionStatement.accept (package:kernel/ast.dart:9128:43)
#34     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#35     List.forEach (dart:core-patch/growable_array.dart:417:8)
#36     Printer.writeFunctionBody (package:kernel/text/ast_to_text.dart:792:23)
#37     Printer.writeFunction (package:kernel/text/ast_to_text.dart:759:7)
#38     Printer.visitFunctionExpression (package:kernel/text/ast_to_text.dart:1866:5)
#39     FunctionExpression.accept (package:kernel/ast.dart:8588:44)
#40     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#41     Printer.writeList (package:kernel/text/ast_to_text.dart:913:15)
#42     Printer.visitArguments (package:kernel/text/ast_to_text.dart:2487:5)
#43     Arguments.accept (package:kernel/ast.dart:5394:38)
#44     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#45     Printer.visitStaticInvocation (package:kernel/text/ast_to_text.dart:1587:5)
#46     StaticInvocation.accept (package:kernel/ast.dart:6582:44)
#47     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#48     Printer.writeExpression (package:kernel/text/ast_to_text.dart:1027:5)
#49     Printer.visitInstanceGet (package:kernel/text/ast_to_text.dart:2046:5)
#50     InstanceGet.accept (package:kernel/ast.dart:4556:44)
#51     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#52     Printer.writeList (package:kernel/text/ast_to_text.dart:913:15)
#53     Printer.visitArguments (package:kernel/text/ast_to_text.dart:2487:5)
#54     Arguments.accept (package:kernel/ast.dart:5394:38)
#55     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#56     Printer.visitInstanceInvocation (package:kernel/text/ast_to_text.dart:1532:5)
#57     InstanceInvocation.accept (package:kernel/ast.dart:5773:44)
#58     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#59     Printer.writeExpression (package:kernel/text/ast_to_text.dart:1027:5)
#60     Printer.visitReturnStatement (package:kernel/text/ast_to_text.dart:2368:7)
#61     ReturnStatement.accept (package:kernel/ast.dart:10140:43)
#62     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#63     Printer.writeBody (package:kernel/text/ast_to_text.dart:853:7)
#64     Printer.writeFunctionBody (package:kernel/text/ast_to_text.dart:804:7)
#65     Printer.writeFunction (package:kernel/text/ast_to_text.dart:759:7)
#66     Printer.visitProcedure (package:kernel/text/ast_to_text.dart:1157:9)
#67     Procedure.accept (package:kernel/ast.dart:3228:40)
#68     Printer.writeNode (package:kernel/text/ast_to_text.dart:621:12)
#69     List.forEach (dart:core-patch/growable_array.dart:417:8)
#70     Printer.writeStandardLibraryContent (package:kernel/text/ast_to_text.dart:454:24)
#71     Printer.writeComponentFile (package:kernel/text/ast_to_text.dart:531:13)
#72     writeComponentToText (package:kernel/kernel.dart:76:8)
#73     main (package:kernel/src/tool/dump.dart:28:3)
#74     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:33)
#75     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
Dart SDK version: 3.5.1 (stable) (Tue Aug 13 21:02:17 2024 +0000) on "windows_x64"
mraleph commented 1 month ago

Lets try this instead (I added a try/catch to suppress this error):

dump.dill.zip

LefebvreIlyas commented 1 month ago

The command now works, I've found 2 cases that occur several times: String* and E* always used as generics.

This is part of the code of my package and its use in the application. I'll try to produce a minimal example reproducing the bug.

mraleph commented 1 month ago

@chloestefantsova do you happen to recall any recent fixes in CFE which could be happening here? (e.g. CFE incorrectly producing legacy nullability on types?).

@LefebvreIlyas it could help if you post few lines of code which contain these types and the context from which they originate (e.g. declaration of the class). You can simply replace all proprietary names with C1, C2 etc. We might be able to deduce the nature of the bug faster simply from looking at the shape of the code.

LefebvreIlyas commented 1 month ago

This was my aim with the minimum example, as the code is quite complex. Here it is, however, I've left the names as they are for easier understanding. I hope it helps you understand what's going on.

FormField

abstract class FormField<V, E, S extends FormFieldState<V, E>> extends Cubit<S> {}

abstract class FormFieldState<V, E> extends Equatable {}

ContainerField

abstract class ContainerField<V, EV, C, EC, S extends ContainerFieldState<V, EV, C, EC>> extends FormField<C, EC, S> {}

abstract class ContainerFieldState<V, EV, C, EC> extends FormFieldState<C, EC> {}

Typedefs

typedef AnyFormFieldValue = dynamic;

typedef AnyContainerFieldE<E> = ContainerField<AnyFormFieldValue, E, AnyFormFieldValue, E, AnyContainerFieldStateE<E>>;

typedef AnyContainerFieldStateE<E> = ContainerFieldState<AnyFormFieldValue, E, AnyFormFieldValue, E>;

typedef ContainerFieldWithStringError = AnyContainerFieldE<String>;

Dill code with bad type

// The file don't contains the typedef definition of AnyContainerFieldStateE like ContainerFieldWithStringError but instead
AnyContainerFieldE<E extends core::Object? = dynamic> = for13::ContainerField<dynamic, E%, dynamic, E%, for13::ContainerFieldState<dynamic, E*, dynamic, E*>>;

typedef ContainerFieldWithStringError = for13::ContainerField<dynamic, core::String, dynamic, core::String, for13::ContainerFieldState<dynamic, core::String*, dynamic, core::String*>>;
mraleph commented 1 month ago

Thanks! I have tried compiling this code and it does not produce legacy nullability on typedefs. So there must be something else in play additionally. Lets wait and see if @chloestefantsova can maybe recognize where the problem can possibly be.

LefebvreIlyas commented 1 month ago

Thanks to you for your support!

That's what I've just noticed too 😢 I'll keep looking also for a minimim example having the bug.

chloestefantsova commented 1 month ago

@chloestefantsova do you happen to recall any recent fixes in CFE which could be happening here? (e.g. CFE incorrectly producing legacy nullability on types?).

I can't recall any recent changes in that area, but the legacy nullability was deprecated somewhat recently by @johnniwinther. We might see an old and undetected issue surfacing here. I'll try to see where a legacy nullability can be assigned in general and hopefully reproduce the issue that way.

LefebvreIlyas commented 1 month ago

Hello @mraleph, @chloestefantsova

The error suddenly disappeared after an update. 🥳 Many thanks to the authors of the commits who corrected the problem and to you for your help and support !

Version without error

    • Flutter version 3.25.0-1.0.pre.189 on channel main at C:\Flutter
    • Framework revision 055350f84a (30 minutes ago), 2024-08-29 11:56:39 -0700
    • Engine revision 8c27891859
    • Dart version 3.6.0 (build 3.6.0-195.0.dev)
    • DevTools version 2.39.0

Version with error

    • Flutter version 3.25.0-1.0.pre.72 on channel main at C:\Flutter
    • Framework revision 503f0f803f (8 days ago), 2024-08-21 14:38:30 -0400
    • Engine revision b94e009703
    • Dart version 3.6.0 (build 3.6.0-164.0.dev)
    • DevTools version 2.39.0-dev.15

I will continue to do some tests on other applications, if it's ok I will close the issue if it's ok for you.