-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Description
The generated Dart code for ANTLR grammars, when targeting web platforms, can produce integer literals that exceed the maximum safe integer limit in JavaScript (
This issue specifically affects web builds and is a direct result of the difference between 64-bit integer representation in most native environments and the 53-bit safe integer limit in JavaScript's number type.
Error Message
Error: The integer literal 1295065285207669298 can't be represented exactly in JavaScript.
Try changing the literal to something that can be represented in JavaScript. In JavaScript 1295065285207669248 is the nearest value that can be represented exactly.
Affected Grammar
This issue is consistently reproducible with the objc
grammar from the antlr/grammars-v4
repository.
Steps to Reproduce
To reproduce this issue, run the following commands (just generate dart-parser and import it or add checkVersion call to prevent unused import warning):
# Clone the repository with the grammars
git clone https://github.com/antlr/grammars-v4.git
# Create a new Flutter project for web
flutter create --platforms web flutter_web_error
cd flutter_web_error/
# Add the antlr4 package
flutter pub add antlr4
# Generate Dart code from the objc grammar
antlr4 -visitor -o lib/antlr4 -Xexact-output-dir -Dlanguage=Dart ../grammars-v4/objc/ObjectiveCParser.g4 ../grammars-v4/objc/ObjectiveCLexer.g4
# Add ANTLR generated parser import to main.dart to trigger the error on run
printf "import 'package:flutter_web_error/antlr4/ObjectiveCParser.dart';\n$(cat lib/main.dart)" > lib/main.dart
# Run the web application
flutter run