Tensegritics / Tensegritics/ClojureDart
Type cast errors in Flutter Web release builds (dart2js/dart2wasm)
Nobody has claimed this yet.
- Dominant language
- Clojure
- Stars
- 1.6k
- Forks
- 119
- PR merge metrics
- No merged PRs in 30d
Description
Summary
ClojureDart-generated Dart code fails with type cast errors when compiled for Flutter Web in release mode, but works correctly in debug and profile modes.
Environment
- Flutter SDK: 3.10.4+
- Platform: Flutter Web
- ClojureDart: latest
- OS: Windows
Steps to Reproduce
- Create a ClojureDart Flutter project with standard data structures (records, atoms, persistent hash maps)
- Run flutter run -d chrome → Works correctly
- Run flutter build web then deploy → Fails with type errors
- Run flutter build web --profile then deploy → Works correctly
Error Messages
- dart2js (release) build:
TypeError: Instance of 'minified:ba': type 'minified:ba' is not a subtype of type 'num'
- dart2wasm (--wasm) build:
Type 'minified:Class1412' is not a subtype of type 'minified:Class2786' in type cast
Suspected Cause
The error occurs in ClojureDart's core data structures when values are cast to num (e.g., (value as dc.num).toDouble()). In debug mode, the types are correct, but dart2js/dart2wasm's aggressive optimizations in release mode appear to break type inference, causing incorrect types to flow through the cast expressions.
Example from generated code:
.apply(
fontSizeFactor: ((const lcoc_core.Keyword(null, "font-size-factor", ...).$_invoke$1(lcoc_main.theme$v1, )) as dc.num).toDouble(),
fontSizeDelta: ((const lcoc_core.Keyword(null, "font-size-delta", ...).$_invoke$1(lcoc_main.theme$v1, )) as dc.num).toDouble(),
)
The $_invoke$1 call returns a value from a PersistentHashMap, and the cast to dc.num fails in optimized builds.
Workaround
Building with flutter build web --profile produces a working build, though it's larger and not ideal for production.
Additional Context
The app loads partially (some widgets renders) before crashing
The issue affects PersistentHashMap lookups and possibly other core data structure operations
Tested with both dart2js (default) and dart2wasm (--wasm) - both fail similarly
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with flutter build web and compare it with the working debug and profile builds, including the dart2js and dart2wasm cases. Start by tracing the generated PersistentHashMap lookup and the as dc.num casts shown in the issue. Done means release web builds run without the reported type-cast errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flutter, wasm
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100