8000 Meta-issue for NNBD no-implicit-downcast and int/double operations. · Issue #725 · dart-lang/language · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Meta-issue for NNBD no-implicit-downcast and int/double operations. #725

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

Closed
2 tasks done
lrhn opened this issue Dec 6, 2019 · 3 comments
Closed
2 tasks done

Meta-issue for NNBD no-implicit-downcast and int/double operations. #725

lrhn opened this issue Dec 6, 2019 · 3 comments
Labels
nnbd NNBD related issues request Requests to resolve a particular developer problem

Comments

@lrhn
Copy link
Member
lrhn commented Dec 6, 2019

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.

@lrhn lrhn added request Requests to resolve a particular developer problem nnbd NNBD related issues labels Dec 6, 2019
@eernstg
Copy link
Member
eernstg commented Dec 6, 2019

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.

@leafpetersen
Copy link
Member

Is this resolved now with the num updates?

@lrhn
Copy link
Member Author
lrhn commented Sep 11, 2020

I believe so, with the analyzer having implemented this, we are done.

@lrhn lrhn closed this as completed Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nnbd NNBD related issues request Requests to resolve a particular developer problem
Projects
None yet
Development

No branches or pull requests

3 participants
0