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

The 'variance' language feature is disabled for this library. for Dart 3.5.4 on Flutter Web #57112

Closed
tolotrasamuel opened this issue Nov 17, 2024 · 8 comments
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. needs-info We need additional information from the issue author (auto-closed after 14 days if no response) type-question A question about expected behavior or functionality

Comments

@tolotrasamuel
Copy link

flutter build web --web-renderer html --csp --enable-experiment=variance

In the previous version I tested, 3.4.3 this command above works fine.
3.22.2 │ stable │ 3.22.2 │ 3.4.3 │ Jun 6, 2024 │ │ ● │

I upgraded to 3.5.4 and I got the following errors:

3.24.5 │ stable │ 3.24.5 │ 3.5.4 │ Nov 14, 2024 │ │


../shared_views/lib/views/forms/generic_form/dropdown_field.dart
:39:1:
Error: The 'variance' language feature is disabled for this
library.
inout T, inout
^^^^^
../shared_views/lib/views/radio/radio_builder.dart:3:27:
Error: The 'variance' language feature is disabled for this
library.
class OptionsBuilderParam<inout T> {
                          ^^^^^
../../.pub-cache/hosted/pub.dev/archive-3.4.10/lib/src/bzip2/bzi
p2.dart:5:7:
Error: Method not found: 'UnmodifiableUint8ListView'.
      UnmodifiableUint8ListView(Uint8List(0));
      ^^^^^^^^^^^^^^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/archive-3.4.10/lib/src/bzip2/bzi
p2.dart:7:7:
Error: Method not found: 'UnmodifiableUint32ListView'.
      UnmodifiableUint32ListView(Uint32List(0));
      ^^^^^^^^^^^^^^^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/archive-3.4.10/lib/src/bzip2/bzi
p2.dart:9:7:
Error: Method not found: 'UnmodifiableInt32ListView'.
      UnmodifiableInt32ListView(Int32List(0));
      ^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Compilation failed.
  Command:
  /Users/me/fvm/versions/3.24.5/bin/cache/dart-sdk/bin/dart
  --disable-dart-dev
  /Users/me/fvm/versions/3.24.5/bin/cache/dart-sdk/bin/snaps
  hots/dart2js.dart.snapshot
  --platform-binaries=/Users/me/fvm/versions/3.24.5/bin/cach
  e/flutter_web_sdk/kernel --invoker=flutter_tool
  --enable-experiment=variance -Ddart.vm.product=true
  -DFLUTTER_WEB_AUTO_DETECT=false -DFLUTTER_WEB_USE_SKIA=false
  -DFLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-ca
  nvaskit/a18df97ca57a249df5d8d68cd0820600223ce262/
  --native-null-assertions --no-source-maps -o
  /Users/me/StudioProjects/project/.dart_tool/flutter_bu
  ild/091ff8fe595dc038c06c28bb4d39e856/app.dill
  --packages=.dart_tool/package_config.json --cfe-only
  /Users/me/StudioProjects/project/.dart_tool/flutter_bu
  ild/091ff8fe595dc038c06c28bb4d39e856/main.dart
#0      RunResult.throwException (package:flutter_tools/src/base/process.dart:122:5)
#1      _DefaultProcessUtils.run (package:flutter_tools/src/base/process.dart:370:19)
<asynchronous suspension>
#2      Dart2JSTarget.build (package:flutter_tools/src/build_system/targets/web.dart:203:5)
<asynchronous suspension>
#3      _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:875:9)
<asynchronous suspension>
#4      Future.wait.<anonymous closure> (dart:async/future.dart:534:21)
<asynchronous suspension>
#5      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:813:32)
<asynchronous suspension>
#6      Future.wait.<anonymous closure> (dart:async/future.dart:534:21)
<asynchronous suspension>
#7      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:813:32)
<asynchronous suspension>
#8      FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:635:16)
<asynchronous suspension>
#9      WebBuilder.buildWeb (package:flutter_tools/src/web/compile.dart:92:34)
<asynchronous suspension>
#10     BuildWebCommand.runCommand (package:flutter_tools/src/commands/build_web.dart:230:5)
<asynchronous suspension>
#11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1408:27)
<asynchronous suspension>
#12     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#13     CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
#14     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:420:9)
<asynchronous suspension>
#15     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#16     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:364:5)
<asynchronous suspension>
#17     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:130:9)
<asynchronous suspension>
#18     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
<asynchronous suspension>
#19     main (package:flutter_tools/executable.dart:93:3)
<asynchronous suspension>

Compiling lib/main.dart for the Web...                             40.4s
Error: Failed to compile application for the Web.

It is worth nothing that this does not occur on Android and iOS build, but I faced it on Web.

@dart-github-bot
Copy link
Collaborator

Summary: Upgrading Flutter from 3.4.3 to 3.5.4 caused build errors on web. The variance language feature is disabled, and archive package methods are missing.

@dart-github-bot dart-github-bot added area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Nov 17, 2024
@eernstg
Copy link
Member

eernstg commented Nov 17, 2024

@tolotrasamuel, perhaps it would be useful for you to emulate invariance rather than trying to use --enable-experiment=variance?

I think we already touched upon this in a different thread, but the point is that the variance experiment doesn't include an implementation of the feature in the backends. This implies that the run-time behavior is wrong (explicitly declared variance is ignored, and every type parameter is consider dynamically-checked covariant at run time).

An example is given here: dart-lang/language#524 (comment).

If you are able to use the emulation then you will have the full semantics at run-time and the full static checking at compile-time. The other side of the coin is that you can't use contravariance, it only works for invariance.

@tolotrasamuel
Copy link
Author

In our previous discussion, we discussed that there are two ways to simulate the behavior of inout.

The first approach involves wrapping the field in a private method. However, this workaround has its drawbacks. It requires wrapping multiple callback fields in private methods, which can become cumbersome and lead to code that is difficult to maintain and read when there are many such methods.

The second approach uses typedef Inv<X> = X Function(X);. While this method produce a slightly similar behavior, it doesn't truly simulate inout. Instead, it results in a different behavior, specifically one where subtype relationships are not preserved.

For these reasons, I opted to use the inout experimental approach, as it is the cleanest solution available. Unfortunately, it does not work with Flutter Web on the latest stable Dart version (3.5.4).

@eernstg
Copy link
Member

eernstg commented Nov 19, 2024

OK! However, it is actually the typedef approach that emulates inout. I wrote about this in more detail here.

@biggs0125
Copy link

A couple questions that might help debug the issue of the variance flag being marked as disabled:

  1. Can you verify if this is just an issue with the variance flag or if you're seeing this same issue for other experiments as well?
  2. Does this only happen when you target the web or all backends?

I tried reproducing this at Flutter head and the --enable-experiment=variance flag is working as expected. So it's possible this will be fixed in a later Flutter version.

@lrhn
Copy link
Member

lrhn commented Nov 20, 2024

Experiment flags only works for code that is on the most recent language version, which is (theoretically) the language version the experiment is written to work with.

If your pubspec has an sdk: ^3.4.0, then the experiment flag won't enable the feature for that code when using a Dart 3.5.0 SDK.

@lrhn lrhn added needs-info We need additional information from the issue author (auto-closed after 14 days if no response) type-question A question about expected behavior or functionality area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. and removed type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. labels Nov 20, 2024
Copy link

github-actions bot commented Dec 5, 2024

Without additional information we're not able to resolve this issue. Feel free to add more info or respond to any questions above and we can reopen the case. Thanks for your contribution!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2024
@tolotrasamuel
Copy link
Author

Thanks @lrhn that was the issue.

Moving forward, I suggest adding this statement in the Experimental Flag Web because I would have never guessed.

Experiment flags only works for code that is on the most recent language version, which is (theoretically) the language version the experiment is written to work with.

Also, I worked on a Flutter package, and it is using a local package that uses the experiemental flag. Both the main project and the package needed to increase the sdk version restriction to the latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-cli Use area-dart-cli for issues related to the 'dart' command like tool. needs-info We need additional information from the issue author (auto-closed after 14 days if no response) type-question A question about expected behavior or functionality
Projects
None yet
Development

No branches or pull requests

5 participants