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.21k stars 1.57k forks source link

Build failures in Flutter Beta Channel #56950

Open jezell opened 2 hours ago

jezell commented 2 hours ago

This gist fails to compile in Flutter Beta 3.27.0. There seems to be a breaking change dart2js in compiler behavior relating to anonymous functions / dynamics, but I'm having a hard time reducing to a simple repro.

https://gist.github.com/jezell/e6bb1adf6f57235d2cfb03dae1508746

result of flutter build web on beta

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 3.27.0-0.1.pre, on macOS 14.5 23F79 darwin-arm64, locale en-US)

Target dart2js failed: ProcessException: Process exited abnormally with exit code 1:
lib/main.dart:16:9:
Error: Function converted via 'toJS' contains invalid types in its function signature: 'Null Function(*dynamic*)'.
      }.toJS,
        ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/rtc_peerconnection_impl.dart:30:11:
Error: Function converted via 'toJS' contains invalid types in its function signature: 'Null Function(*dynamic*)'.
        }.toJS);
          ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/rtc_peerconnection_impl.dart:38:11:
Error: Function converted via 'toJS' contains invalid types in its function signature: 'Null Function(*dynamic*)'.
        }.toJS);
          ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/rtc_peerconnection_impl.dart:78:11:
Error: Function converted via 'toJS' contains invalid types in its function signature: 'Null Function(*dynamic*)'.
        }.toJS);
          ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/rtc_peerconnection_impl.dart:83:8:
Error: Function converted via 'toJS' contains invalid types in its function signature: 'Null Function(*dynamic*)'.
    }).toJS;
       ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/rtc_peerconnection_impl.dart:90:11:
Error: Function converted via 'toJS' contains invalid types in its function signature: 'Null Function(*dynamic*)'.
        }.toJS);
          ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/rtc_peerconnection_impl.dart:99:13:
Error: Function converted via 'toJS' contains invalid types in its function signature: 'Null Function(*dynamic*)'.
          }.toJS);
            ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/rtc_peerconnection_impl.dart:106:11:
Error: Function converted via 'toJS' contains invalid types in its function signature: 'Null Function(*dynamic*)'.
        }.toJS);
          ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/media_stream_track_impl.dart:12:68:
Error: Function converted via 'toJS' contains invalid types in its function signature: '*dynamic* Function(*dynamic*)'.
    jsTrack.addEventListener('ended', ((event) => onEnded?.call()).toJS);
                                                                   ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/media_stream_track_impl.dart:13:66:
Error: Function converted via 'toJS' contains invalid types in its function signature: '*dynamic* Function(*dynamic*)'.
    jsTrack.addEventListener('mute', ((event) => onMute?.call()).toJS);
                                                                 ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/media_stream_track_impl.dart:14:70:
Error: Function converted via 'toJS' contains invalid types in its function signature: '*dynamic* Function(*dynamic*)'.
    jsTrack.addEventListener('unmute', ((event) => onUnMute?.call()).toJS);
                                                                     ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/rtc_data_channel_impl.dart:17:11:
Error: Function converted via 'toJS' contains invalid types in its function signature: 'Null Function(*dynamic*)'.
        }.toJS,
          ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/rtc_data_channel_impl.dart:25:11:
Error: Function converted via 'toJS' contains invalid types in its function signature: 'Null Function(*dynamic*)'.
        }.toJS,
          ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/rtc_data_channel_impl.dart:33:11:
Error: Function converted via 'toJS' contains invalid types in its function signature: '*Future<Null>* Function(MessageEvent)'.
        }.toJS,
          ^
../../.pub-cache/git/dart-webrtc-baf6d5bc3d63596a81c749118dffb1181464a5ae/lib/src/rtc_data_channel_impl.dart:39:11:
Error: Function converted via 'toJS' contains invalid types in its function signature: 'Null Function(*dynamic*)'.
        }.toJS,
          ^
Error: Compilation failed.
  Command: /usr/local/lib/flutter/bin/cache/dart-sdk/bin/dart /usr/local/lib/flutter/bin/cache/dart-sdk/bin/snapshots/dart2js.dart.snapshot
  --platform-binaries=/usr/local/lib/flutter/bin/cache/flutter_web_sdk/kernel --invoker=flutter_tool -Ddart.vm.product=true -DFLUTTER_WEB_AUTO_DETECT=false -DFLUTTER_WEB_USE_SKIA=true
  -DFLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/af0f0d559c8a87d912a20971bbd84afc80a54b0f/ --native-null-assertions --no-source-maps -o
  /Users/jesseezell/dart-test/test/.dart_tool/flutter_build/8ddbe17246e55b52a4c5427e337c9d5c/app.dill --packages=/Users/jesseezell/dart-test/test/.dart_tool/package_config.json --cfe-only
  /Users/jesseezell/dart-test/test/.dart_tool/flutter_build/8ddbe17246e55b52a4c5427e337c9d5c/main.dart
#0      RunResult.throwException (package:flutter_tools/src/base/process.dart:122:5)
#1      _DefaultProcessUtils.run (package:flutter_tools/src/base/process.dart:389:19)
<asynchronous suspension>
#2      Dart2JSTarget.build (package:flutter_tools/src/build_system/targets/web.dart:202:5)
<asynchronous suspension>
#3      _BuildInstance._invokeInternal (package:flutter_tools/src/build_system/build_system.dart:891:9)
<asynchronous suspension>
#4      Future.wait.<anonymous closure> (dart:async/future.dart:520:21)
<asynchronous suspension>
#5      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:829:32)
<asynchronous suspension>
#6      Future.wait.<anonymous closure> (dart:async/future.dart:520:21)
<asynchronous suspension>
#7      _BuildInstance.invokeTarget (package:flutter_tools/src/build_system/build_system.dart:829:32)
<asynchronous suspension>
#8      FlutterBuildSystem.build (package:flutter_tools/src/build_system/build_system.dart:651: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:233:5)
<asynchronous suspension>
#11     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1450: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:421: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:131: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:94:3)
<asynchronous suspension>

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

result on stable, build succeeds:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.3, on macOS 14.5 23F79 darwin-arm64, locale en-US)
flutter build web

Font asset "CupertinoIcons.ttf" was tree-shaken, reducing it from 257628 to 1172 bytes (99.5% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 7760 bytes (99.5% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Compiling lib/main.dart for the Web...                             17.2s
✓ Built build/web

Attempting to reduce the problem by pulling some of the failing code into main fails in both stable and beta, yet importing the module itself only fails in beta.

  final dynamic Function(web.MessageEvent event)? onMessage = null;

  Function(int currentAmount)? onBufferedAmountLow;

  int? bufferedAmount;
  web.window.addEventListener(
      'bufferedamountlow',
      (_) {
        onBufferedAmountLow?.call(bufferedAmount ?? 0);
      }.toJS,
      false.toJS);

I can fix the problem in beta by assigning the anonymous functions to typed function variables, before calling toJS but I can't explain why the compiler fails in beta and works in stable.

dart-github-bot commented 2 hours ago

Summary: The user is experiencing build failures in Flutter Beta 3.27.0 when using the dart2js compiler. The issue appears to be related to a breaking change in the compiler's behavior regarding anonymous functions and dynamic types. The user has provided a code snippet and build logs to illustrate the problem.