-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
The BigInt class does not have a const constructor #33893
Comments
The extremely short version is that the rpc package makes use of an annotation, This annotation class has properties that refer to the minimum and maximum value of integers as well as the kind of integer (including uint64). For example: Without a way to refer to constant BigInts (and preferably, BigInt literals), the ported API is going to look pretty ugly inside and out -- possibly requiring the use of string representations of integers and even more runtime type checking than these classes already perform. Several other workarounds have proven impractical or even more ugly so far, but I'm open to suggestions. |
Not that this is a great idea, but it is an idea, AngularDart has recommended static methods, i.e.: BigInt getMinValue() => ...
@ApiProperty(minValue: getMinValue)
... ... for this reason (with other, non-const classes). |
@matanlurey Hmm. That seems like it'd be more helpful if we had BigInt non-const literals(??) but no const constructor. Otherwise it seems like I'm just exporting the ugliness of string parsing to my clients. But maybe there are use cases where this would save us from always having to parse strings. |
Yeah. It's sad, but it's an option :-/ |
Const constructors for BigInt should be trivial in DDC and soon in Dart2JS as in JavaScript running on Chrome |
Literals would be tricky since, as stated above, the values aren't really constant. All other number literals are constant values. Integrating One option is to add a |
I think integrating BigInt into the language is the only way to go long term if we want to solve this -- if prohibiting extending/implementing BigInt makes that more possible I'd be in favor. In the meantime, my workaround (BigInt literals as strings where we need them const, and runtime type checking) seems to function without invasive client code changes. Despite it looking a little ridiculous and being slow. :-) |
+100 on integrating into the language. On the web site, a const compatible version of BigInt is being integrated into JS so this is something that could be efficiently done on both the VM and Dart2Js. |
Note that dart2js still has to support old browsers like ie11, so even though we'd take advantage of Bigints in JS engines once available, we wont be able to do it always. I guess that if we hide the entire big-int implementation in our patch files, we could present it as a const type at that point, regardless of how it's implemented |
@lhrn I would also like the specification to be a little bit more specific about what you can always guarantee about Dart integers. If >=53 bit precision must always available, that should be explicitly stated somewhere in the language specification. The Appendix entry strongly implies that, but the specification seems to reference the implementation for precision. If I were implementing Dart on a Commodore 64, limiting precision to 8 bits would still arguably be in spec as that would fall into the category of other considerations. |
@lrhn said "We should probably prohibit people from extending or implementing BigInt if we want that." Can we at least 'seal' the BigInt interface class to preserve flexibility? |
Now that IE11 support is going to be deprecated soon, it may be reasonable to revisit BigInt integration into language. Literal values could be supported just like in JS with |
Hi, is there any updates? For example, for a function with BigInt arguments, how to provide a default value for it given no const constructor? Thanks! Related: fzyzcjy/flutter_rust_bridge#2035 |
The BigInt class lacks a const constructor. This causes problems porting some Dart 1 code that used > 64 bit ints to Dart 2 as const values have to stop being const.
@jcollins-g has more details on the challenges this causes making the rpc library work with Dart 2.
The text was updated successfully, but these errors were encountered: