Meta-issue for NNBD no-implicit-downcast and int/double operations. · Issue #725 · dart-lang/language · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Dart int and double types have special rules in the static type system which allows, effectively, limited overloading on the types of operations. For example if x has static type int then x + x has static type int, even though the signature of int.operator+ is num Function(num).
Other operations are not special-cased and always return num, but they always work in practice because of the implicit downcast from num to the type the user expects. For example pow from dart:math always return num, but it promises that pow(2, 8) is an integer because both arguments are (positive) integers.
When NNBD removes implicit downcast, some numeric operations will become much less usable in practice, and may require adding explicit downcasts in non-obvious places.
This issue tries to collect issues related to this in the hope that we can solve them in a unified way.
Here's a feature which is related to this request: Case functions (#148) are designed to make it possible to have a single function with multiple static typings, e.g., such that max(a, b) can be given the type int when both a and b have static type int, and double if a and b have type double, and num otherwise.
The point is that the function can have several "cases" in the body, and they are at the same time available for static selection (so we can make the choice to call a specific case at a given call site, which will give use good performance and tight typing), and the function still works as a whole (where the cases work basically like a regular type case statement) such that it can be invoked dynamically, torn off, etc.
That approach would allow us to handle a number of cases that otherwise seem to call for special exceptions.
The Dart
int
anddouble
types have special rules in the static type system which allows, effectively, limited overloading on the types of operations. For example ifx
has static typeint
thenx + x
has static type int, even though the signature ofint.operator+
isnum Function(num)
.Other operations are not special-cased and always return
num
, but they always work in practice because of the implicit downcast fromnum
to the type the user expects. For examplepow
fromdart:math
always returnnum
, but it promises thatpow(2, 8)
is an integer because both arguments are (positive) integers.When NNBD removes implicit downcast, some numeric operations will become much less usable in practice, and may require adding explicit downcasts in non-obvious places.
This issue tries to collect issues related to this in the hope that we can solve them in a unified way.
The text was updated successfully, but these errors were encountered: