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

dart2js not compiling lambda with the correct parameter type. #56822

Open
gmpassos opened this issue Sep 30, 2024 · 6 comments
Open

dart2js not compiling lambda with the correct parameter type. #56822

gmpassos opened this issue Sep 30, 2024 · 6 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@gmpassos
Copy link
Contributor

I've encountered an unusual issue with dart2js and have isolated a code snippet that reproduces the bug:

  • The code compiles successfully in both DDC and dart2js.
  • It runs as expected in DDC.
  • However, it fails to run when compiled with dart2js (in webdev release mode).
import 'dart:html';

void main() async {
  // Trigger voice loading...
  window.speechSynthesis?.getVoices();
  
  print('Loading voices...');
  await Future.delayed(Duration(seconds: 3));

  var voices = window.speechSynthesis?.getVoices();

  // Expects a non-empty list:
  print(voices);
  
  // Fails to call the `map` lambda when compiled by `dart2js`:
  var langs = voices?.map((e) => e.lang).toList();
  
  print(langs);  
}
  • Note that the list voices needs to be populated to reproduce the bug.

  • I'm not sure of the exact issue, but it seems that the compiled JS is expecting a different type for the map lambda parameter.


Run it:

 webdev serve -r

Open in the browser: http://127.0.0.1:8080

Browser Console output:

main.dart.js:3782 Loading voices...
main.dart.js:3782 [[object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice], [object SpeechSynthesisVoice]]
main.dart.js:535 Uncaught Error: TypeError: Closure 'main_closure': type '(SpeechSynthesisVoice) => String?' is not a subtype of type '(dynamic) => String?'
    at Object.wrapException (main.dart.js:535:43)
    at Object._failedAsCheck (main.dart.js:1581:15)
    at Rti._generalAsCheckImplementation [as _as] (main.dart.js:1570:9)
    at Rti._installSpecializedAsCheck (main.dart.js:1517:22)
    at JavaScriptObject.map$1$1 (main.dart.js:3860:80)
    at Object.map$1$1$ax (main.dart.js:371:44)
    at main.dart.js:3764:24
    at _wrapJsFunctionForAsync_closure.$protected (main.dart.js:2844:15)
    at _wrapJsFunctionForAsync_closure.call$2 (main.dart.js:4358:12)
    at _awaitOnObject_closure.call$1 (main.dart.js:4346:32)
wrapException @ main.dart.js:535
Error__throw @ main.dart.js:3282
Error_throwWithStackTrace @ main.dart.js:3330
call$0 @ main.dart.js:4727
_microtaskLoop @ main.dart.js:3038
_startMicrotaskLoop @ main.dart.js:3044
call$1 @ main.dart.js:4303
childList
call$1 @ main.dart.js:4313
_scheduleAsyncCallback @ main.dart.js:3058
_schedulePriorityAsyncCallback @ main.dart.js:3066
_rootHandleError @ main.dart.js:3103
_Future__propagateToListeners @ main.dart.js:2932
_completeError$2 @ main.dart.js:4548
_asyncRethrow @ main.dart.js:2817
(anonymous) @ main.dart.js:3745
(anonymous) @ main.dart.js:2844
call$2 @ main.dart.js:4358
call$1 @ main.dart.js:4346
runUnary$2$2 @ main.dart.js:4760
call$0 @ main.dart.js:4687
_Future__propagateToListeners @ main.dart.js:2975
_complete$1 @ main.dart.js:4532
call$0 @ main.dart.js:4374
call$0 @ main.dart.js:4339
setTimeout
_TimerImpl$2 @ main.dart.js:4332
_TimerImpl$ @ main.dart.js:2782
Timer__createTimer @ main.dart.js:2778
Timer_Timer @ main.dart.js:3099
Future_Future$delayed @ main.dart.js:2874
(anonymous) @ main.dart.js:3755
(anonymous) @ main.dart.js:2844
call$2 @ main.dart.js:4358
_asyncStartSync @ main.dart.js:2789
main @ main.dart.js:3772
(anonymous) @ main.dart.js:6201
(anonymous) @ main.dart.js:6182
dartProgram @ main.dart.js:6195
(anonymous) @ main.dart.js:6204Understand this error

$> dart info

If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

#### General info

- Dart 3.5.3 (stable) (Wed Sep 11 16:22:47 2024 +0000) on "macos_x64"
- on macos / Version 12.7.4 (Build 21H1123)
- locale is en-BR

#### Project info

- sdk constraint: '^3.5.2'
- dependencies: web
- dev_dependencies: build_runner, build_web_compilers, lints

#### Process info

No Dart processes found.

pubspec.lock:

# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
  _fe_analyzer_shared:
    dependency: transitive
    description:
      name: _fe_analyzer_shared
      sha256: "45cfa8471b89fb6643fe9bf51bd7931a76b8f5ec2d65de4fb176dba8d4f22c77"
      url: "https://pub.dev"
    source: hosted
    version: "73.0.0"
  _macros:
    dependency: transitive
    description: dart
    source: sdk
    version: "0.3.2"
  analyzer:
    dependency: transitive
    description:
      name: analyzer
      sha256: "4959fec185fe70cce007c57e9ab6983101dbe593d2bf8bbfb4453aaec0cf470a"
      url: "https://pub.dev"
    source: hosted
    version: "6.8.0"
  archive:
    dependency: transitive
    description:
      name: archive
      sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d
      url: "https://pub.dev"
    source: hosted
    version: "3.6.1"
  args:
    dependency: transitive
    description:
      name: args
      sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a"
      url: "https://pub.dev"
    source: hosted
    version: "2.5.0"
  async:
    dependency: transitive
    description:
      name: async
      sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
      url: "https://pub.dev"
    source: hosted
    version: "2.11.0"
  bazel_worker:
    dependency: transitive
    description:
      name: bazel_worker
      sha256: "4eef19cc486c289e4b06c69d0f6f3192e85cc93c25d4d15d02afb205e388d2f0"
      url: "https://pub.dev"
    source: hosted
    version: "1.1.1"
  boolean_selector:
    dependency: transitive
    description:
      name: boolean_selector
      sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
      url: "https://pub.dev"
    source: hosted
    version: "2.1.1"
  build:
    dependency: transitive
    description:
      name: build
      sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0"
      url: "https://pub.dev"
    source: hosted
    version: "2.4.1"
  build_config:
    dependency: transitive
    description:
      name: build_config
      sha256: bf80fcfb46a29945b423bd9aad884590fb1dc69b330a4d4700cac476af1708d1
      url: "https://pub.dev"
    source: hosted
    version: "1.1.1"
  build_daemon:
    dependency: transitive
    description:
      name: build_daemon
      sha256: "79b2aef6ac2ed00046867ed354c88778c9c0f029df8a20fe10b5436826721ef9"
      url: "https://pub.dev"
    source: hosted
    version: "4.0.2"
  build_modules:
    dependency: transitive
    description:
      name: build_modules
      sha256: "403ba034d94f1a0f26362fe14fd83e9ff33644f5cbe879982920e3d209650b43"
      url: "https://pub.dev"
    source: hosted
    version: "5.0.9"
  build_resolvers:
    dependency: transitive
    description:
      name: build_resolvers
      sha256: "339086358431fa15d7eca8b6a36e5d783728cf025e559b834f4609a1fcfb7b0a"
      url: "https://pub.dev"
    source: hosted
    version: "2.4.2"
  build_runner:
    dependency: "direct dev"
    description:
      name: build_runner
      sha256: "028819cfb90051c6b5440c7e574d1896f8037e3c96cf17aaeb054c9311cfbf4d"
      url: "https://pub.dev"
    source: hosted
    version: "2.4.13"
  build_runner_core:
    dependency: transitive
    description:
      name: build_runner_core
      sha256: f8126682b87a7282a339b871298cc12009cb67109cfa1614d6436fb0289193e0
      url: "https://pub.dev"
    source: hosted
    version: "7.3.2"
  build_web_compilers:
    dependency: "direct dev"
    description:
      name: build_web_compilers
      sha256: e8d818410cc8b4dc96c4960ce0ab84fe3f2b0ca6576cc130fd7277b56eba9d68
      url: "https://pub.dev"
    source: hosted
    version: "4.0.11"
  built_collection:
    dependency: transitive
    description:
      name: built_collection
      sha256: "376e3dd27b51ea877c28d525560790aee2e6fbb5f20e2f85d5081027d94e2100"
      url: "https://pub.dev"
    source: hosted
    version: "5.1.1"
  built_value:
    dependency: transitive
    description:
      name: built_value
      sha256: c7913a9737ee4007efedaffc968c049fd0f3d0e49109e778edc10de9426005cb
      url: "https://pub.dev"
    source: hosted
    version: "8.9.2"
  checked_yaml:
    dependency: transitive
    description:
      name: checked_yaml
      sha256: feb6bed21949061731a7a75fc5d2aa727cf160b91af9a3e464c5e3a32e28b5ff
      url: "https://pub.dev"
    source: hosted
    version: "2.0.3"
  code_builder:
    dependency: transitive
    description:
      name: code_builder
      sha256: f692079e25e7869c14132d39f223f8eec9830eb76131925143b2129c4bb01b37
      url: "https://pub.dev"
    source: hosted
    version: "4.10.0"
  collection:
    dependency: transitive
    description:
      name: collection
      sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
      url: "https://pub.dev"
    source: hosted
    version: "1.19.0"
  convert:
    dependency: transitive
    description:
      name: convert
      sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
      url: "https://pub.dev"
    source: hosted
    version: "3.1.1"
  crypto:
    dependency: transitive
    description:
      name: crypto
      sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27
      url: "https://pub.dev"
    source: hosted
    version: "3.0.5"
  dart_style:
    dependency: transitive
    description:
      name: dart_style
      sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab"
      url: "https://pub.dev"
    source: hosted
    version: "2.3.7"
  file:
    dependency: transitive
    description:
      name: file
      sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c"
      url: "https://pub.dev"
    source: hosted
    version: "7.0.0"
  fixnum:
    dependency: transitive
    description:
      name: fixnum
      sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1"
      url: "https://pub.dev"
    source: hosted
    version: "1.1.0"
  frontend_server_client:
    dependency: transitive
    description:
      name: frontend_server_client
      sha256: f64a0333a82f30b0cca061bc3d143813a486dc086b574bfb233b7c1372427694
      url: "https://pub.dev"
    source: hosted
    version: "4.0.0"
  glob:
    dependency: transitive
    description:
      name: glob
      sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63"
      url: "https://pub.dev"
    source: hosted
    version: "2.1.2"
  graphs:
    dependency: transitive
    description:
      name: graphs
      sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0"
      url: "https://pub.dev"
    source: hosted
    version: "2.3.2"
  http_multi_server:
    dependency: transitive
    description:
      name: http_multi_server
      sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b"
      url: "https://pub.dev"
    source: hosted
    version: "3.2.1"
  http_parser:
    dependency: transitive
    description:
      name: http_parser
      sha256: "40f592dd352890c3b60fec1b68e786cefb9603e05ff303dbc4dda49b304ecdf4"
      url: "https://pub.dev"
    source: hosted
    version: "4.1.0"
  io:
    dependency: transitive
    description:
      name: io
      sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e"
      url: "https://pub.dev"
    source: hosted
    version: "1.0.4"
  js:
    dependency: transitive
    description:
      name: js
      sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
      url: "https://pub.dev"
    source: hosted
    version: "0.7.1"
  json_annotation:
    dependency: transitive
    description:
      name: json_annotation
      sha256: "1ce844379ca14835a50d2f019a3099f419082cfdd231cd86a142af94dd5c6bb1"
      url: "https://pub.dev"
    source: hosted
    version: "4.9.0"
  lints:
    dependency: "direct dev"
    description:
      name: lints
      sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
      url: "https://pub.dev"
    source: hosted
    version: "4.0.0"
  logging:
    dependency: transitive
    description:
      name: logging
      sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340"
      url: "https://pub.dev"
    source: hosted
    version: "1.2.0"
  macros:
    dependency: transitive
    description:
      name: macros
      sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536"
      url: "https://pub.dev"
    source: hosted
    version: "0.1.2-main.4"
  matcher:
    dependency: transitive
    description:
      name: matcher
      sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
      url: "https://pub.dev"
    source: hosted
    version: "0.12.16+1"
  meta:
    dependency: transitive
    description:
      name: meta
      sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
      url: "https://pub.dev"
    source: hosted
    version: "1.16.0"
  mime:
    dependency: transitive
    description:
      name: mime
      sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6"
      url: "https://pub.dev"
    source: hosted
    version: "2.0.0"
  package_config:
    dependency: transitive
    description:
      name: package_config
      sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd"
      url: "https://pub.dev"
    source: hosted
    version: "2.1.0"
  path:
    dependency: transitive
    description:
      name: path
      sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
      url: "https://pub.dev"
    source: hosted
    version: "1.9.0"
  pool:
    dependency: transitive
    description:
      name: pool
      sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a"
      url: "https://pub.dev"
    source: hosted
    version: "1.5.1"
  protobuf:
    dependency: transitive
    description:
      name: protobuf
      sha256: "68645b24e0716782e58948f8467fd42a880f255096a821f9e7d0ec625b00c84d"
      url: "https://pub.dev"
    source: hosted
    version: "3.1.0"
  pub_semver:
    dependency: transitive
    description:
      name: pub_semver
      sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c"
      url: "https://pub.dev"
    source: hosted
    version: "2.1.4"
  pubspec_parse:
    dependency: transitive
    description:
      name: pubspec_parse
      sha256: c799b721d79eb6ee6fa56f00c04b472dcd44a30d258fac2174a6ec57302678f8
      url: "https://pub.dev"
    source: hosted
    version: "1.3.0"
  scratch_space:
    dependency: transitive
    description:
      name: scratch_space
      sha256: "8510fbff458d733a58fc427057d1ac86303b376d609d6e1bc43f240aad9aa445"
      url: "https://pub.dev"
    source: hosted
    version: "1.0.2"
  shelf:
    dependency: transitive
    description:
      name: shelf
      sha256: e7dd780a7ffb623c57850b33f43309312fc863fb6aa3d276a754bb299839ef12
      url: "https://pub.dev"
    source: hosted
    version: "1.4.2"
  shelf_web_socket:
    dependency: transitive
    description:
      name: shelf_web_socket
      sha256: "073c147238594ecd0d193f3456a5fe91c4b0abbcc68bf5cd95b36c4e194ac611"
      url: "https://pub.dev"
    source: hosted
    version: "2.0.0"
  source_maps:
    dependency: transitive
    description:
      name: source_maps
      sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703"
      url: "https://pub.dev"
    source: hosted
    version: "0.10.12"
  source_span:
    dependency: transitive
    description:
      name: source_span
      sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
      url: "https://pub.dev"
    source: hosted
    version: "1.10.0"
  stack_trace:
    dependency: transitive
    description:
      name: stack_trace
      sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
      url: "https://pub.dev"
    source: hosted
    version: "1.12.0"
  stream_channel:
    dependency: transitive
    description:
      name: stream_channel
      sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
      url: "https://pub.dev"
    source: hosted
    version: "2.1.2"
  stream_transform:
    dependency: transitive
    description:
      name: stream_transform
      sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f"
      url: "https://pub.dev"
    source: hosted
    version: "2.1.0"
  string_scanner:
    dependency: transitive
    description:
      name: string_scanner
      sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
      url: "https://pub.dev"
    source: hosted
    version: "1.3.0"
  term_glyph:
    dependency: transitive
    description:
      name: term_glyph
      sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
      url: "https://pub.dev"
    source: hosted
    version: "1.2.1"
  test_api:
    dependency: transitive
    description:
      name: test_api
      sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
      url: "https://pub.dev"
    source: hosted
    version: "0.7.3"
  timing:
    dependency: transitive
    description:
      name: timing
      sha256: "70a3b636575d4163c477e6de42f247a23b315ae20e86442bebe32d3cabf61c32"
      url: "https://pub.dev"
    source: hosted
    version: "1.0.1"
  typed_data:
    dependency: transitive
    description:
      name: typed_data
      sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
      url: "https://pub.dev"
    source: hosted
    version: "1.3.2"
  watcher:
    dependency: transitive
    description:
      name: watcher
      sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8"
      url: "https://pub.dev"
    source: hosted
    version: "1.1.0"
  web:
    dependency: "direct main"
    description:
      name: web
      sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
      url: "https://pub.dev"
    source: hosted
    version: "0.5.1"
  web_socket:
    dependency: transitive
    description:
      name: web_socket
      sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83"
      url: "https://pub.dev"
    source: hosted
    version: "0.1.6"
  web_socket_channel:
    dependency: transitive
    description:
      name: web_socket_channel
      sha256: "9f187088ed104edd8662ca07af4b124465893caf063ba29758f97af57e61da8f"
      url: "https://pub.dev"
    source: hosted
    version: "3.0.1"
  yaml:
    dependency: transitive
    description:
      name: yaml
      sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5"
      url: "https://pub.dev"
    source: hosted
    version: "3.1.2"
sdks:
  dart: ">=3.5.2 <3.7.0"
@dart-github-bot
Copy link
Collaborator

Summary: The issue is that dart2js fails to compile a lambda function used with the map method on a list of SpeechSynthesisVoice objects, resulting in a type error. The code compiles and runs correctly in DDC, but fails in dart2js webdev release mode.

@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 Sep 30, 2024
@gmpassos
Copy link
Contributor Author

If you need to investigate the generated JS code, force dart2js to not optimize and minify it:

build.yaml:

targets:
  $default:
    builders:
      build_web_compilers:entrypoint:
        options:
          dart2js_args:
            - -O1
            - --no-minify
            - --disable-program-split
            - --no-source-maps

@lrhn lrhn added web-dart2js and removed triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. labels Sep 30, 2024
@fishythefish
Copy link
Member

The inferred static type of the closure is indeed (SpeechSynthesisVoice) => String?. This is expected, since voices has static type List<SpeechSynthesisVoice>?. However, at runtime, print(voices.runtimeType) shows that it's actually JSArray<dynamic>, so .map expects a closure whose parameter type is dynamic, hence the failure.

This is because the array ultimately comes directly from window.speechSynthesis.getVoices() in JS, which doesn't tag the result with the element type.

/cc @srujzs @rakudrama

@srujzs
Copy link
Contributor

srujzs commented Oct 1, 2024

I guess the real issue then is that List<SpeechSynthesisVoice> is not sound here with respect to the generic type, but that's a known issue in how we intercept JSArray. The workaround then would just be to use a lambda that accepts dynamic, but that seems ugly.

Consider using package:web instead where you'll get better static typing: https://github.com/dart-lang/web/blob/8478cd27d574249eca3d41f9135458dfda2762c8/web/lib/src/dom/speech_api.dart#L319.

@gmpassos
Copy link
Contributor Author

gmpassos commented Oct 1, 2024

I guess the real issue then is that List<SpeechSynthesisVoice> is not sound here with respect to the generic type, but that's a known issue in how we intercept JSArray. The workaround then would just be to use a lambda that accepts dynamic, but that seems ugly.

Consider using package:web instead where you'll get better static typing: https://github.com/dart-lang/web/blob/8478cd27d574249eca3d41f9135458dfda2762c8/web/lib/src/dom/speech_api.dart#L319.

For me this is a bug on dart2js, specially because DDC works. This shouldn't be treated as a specific bug on dart:html.

@srujzs
Copy link
Contributor

srujzs commented Oct 1, 2024

For me this is a bug on dart2js, specially because DDC works. This shouldn't be treated as a specific bug on dart:html.

I agree (although DDC working doesn't necessarily indicate that), but this is a problem that materializes specifically for dart:html and older interop versions. There are a few possible solutions e.g. adding the generic type manually, but I'm not sure what all the corner cases there are yet. We can keep this open, but it is preferable to use package:web to avoid these issues that may take much longer to resolve e.g.

import 'package:web/web.dart' as web;

void main() {
  web.window.speechSynthesis.getVoices().toDart.map((e) => e.lang).toList();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

5 participants