Skip to content

WASM error message inconsistency for sublist when range is invalid #61045

Open
@d-markey

Description

@d-markey

Error messages are inconsistent with Dart2Wasm when calling List.sublist() with an invalid range.

I have implemented a custom list and wanted to check my implementation is up to par with lists from Dart's runtime, but came across this weird behavior when checking for error consistency.

Here's a test repro sublist_wasm_bug_test.dart:

import 'package:test/test.dart';

void main() {
  test('sublist bug', () {
    final list = [1, 2, 3, 4, 5, 6, 7];
    final clist = list.cast<int>();

    try {
      list.sublist(4, 3);
    } catch (ex) {
      print('list --> $ex');
    }

    try {
      clist.sublist(4, 3);
    } catch (ex) {
      print('clist --> $ex');
    }
  });
}

Running with dart test .\test\sublist_wasm_bug_test.dart, output is the following:

00:01 +0: [VM, Kernel] sublist bug
list --> RangeError (end): Invalid value: Not in inclusive range 4..7: 3
clist --> RangeError (end): Invalid value: Not in inclusive range 4..7: 3
00:08 +1: [Chrome, Dart2Js] loading test/sublist_wasm_bug_test.dart
Compiled 11,427,586 input bytes (6,447,067 characters source) to 1,063,150 characters JavaScript in 5.67 seconds using N/A MB of memory

00:10 +1: [Chrome, Dart2Js] sublist bug
list --> RangeError (end): Invalid value: Not in inclusive range 4..7: 3
clist --> RangeError (end): Invalid value: Not in inclusive range 4..7: 3
00:16 +2: [Chrome, Dart2Wasm] loading test/sublist_wasm_bug_test.dart
Generated wasm module 'C:\Users\DMA\AppData\Local\Temp\dart_test_368eb21c\test_f43ba83d\sublist_wasm_bug_test.dart.browser_test.dart.wasm', and JS init file 'C:\Users\DMA\AppData\Local\Temp\dart_test_368eb21c\test_f43ba83d\sublist_wasm_bug_test.dart.browser_test.dart.mjs'.

00:18 +2: [Chrome, Dart2Wasm] sublist bug
list --> RangeError (start): Invalid value: Not in inclusive range 0..7: 4
clist --> RangeError (end): Invalid value: Not in inclusive range 4..7: 3
00:18 +3: All tests passed!

WASM output is inconsistent:

list --> RangeError (start): Invalid value: Not in inclusive range 0..7: 4
clist --> RangeError (end): Invalid value: Not in inclusive range 4..7: 3

Test config dart_test.yaml:

platforms:
  - vm
  - chrome

compilers:
  - dart2js
  - dart2wasm

chain_stack_traces: true
concurrency: 1

I'm running on a Dart runtime provided by the latest version of Flutter.

C:\> dart --version
Dart SDK version: 3.8.1 (stable) (Wed May 28 00:47:25 2025 -0700) on "windows_x64"

C:\ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.32.5, on Microsoft Windows [version 10.0.26100.4349], locale fr-FR)
[√] Windows Version (11 Professionnel 64-bit, 24H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.14.5)
[!] Android Studio (version 2021.1)
    X Unable to determine bundled Java version.
[!] Android Studio (version 2023.3)
    X Unable to find bundled Java version.
[√] Android Studio (version 2024.2)
[√] VS Code (version 1.101.2)
[√] Connected device (3 available)
[√] Network resources

! Doctor found issues in 2 categories.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart2wasmIssues for the dart2wasm compiler.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions