-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Consider making num.clamp generic? #30403
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
Comments
See #30402 for some context. |
It won't be easy to do that and preserve the current behavior, or maybe doing it at all. What signature would you suggest for the method? T clamp<T extends num>(T low, T high); This won't work. The problem is that the actual constraint is that Even if we specialize the method for T clamp<T extends ??>(T low, T high); where Maybe just add int int.clampInt(int low, int high);
double double.clampDouble(double low, double high); ? |
Hmm, yeah, unfortunate. Overloading might help here, if you could use the type of the receiver. Another option would be: //num
num clamp(covariant num low, covariant num high);
//int
@override
int clamp(int low, int high) |
Using I think the best solution is to remove Or remove it from |
We are dropping |
Friendly ping for forward movement on this. Spent a few hours debugging an issue with num.clamp() on a double when I was expecting a double out the other side. |
We will allow better static typing through special casing in the type system. |
Currently
num.clamp
is defined as(num, num) -> num
. Making this generic would allow better static typing.cc @floitschG @lrhn
The text was updated successfully, but these errors were encountered: