-
Notifications
You must be signed in to change notification settings - Fork 26
Infer tighter return types for math.max() and math.min() #281
Comments
Maybe I tend to approach these too much from the JS perspective, but ... we could just treat |
FWIW, looks like generic methods DEP would fix this: https://github.com/leafpetersen/dep-generic-methods/blob/master/proposal.md#functions we'll need to implement it soon, at least for the SDK. We're currently ignoring a bunch of unsound casts for a hard coded list of types: https://github.com/dart-lang/dev_compiler/blob/5e0e7d27c36a8d7d6858ddf3b7a66892de6539ae/lib/runtime/_operations.js#L180 see also #28 |
We're hitting this several times in Angular too - see: This should be captured by @leafpetersen 's inference-based generic method work. |
yeah. I have a quick fix about to send out, but Leaf can definite feel free to delete it after :) |
@munificent this is now fixed! I used your suggestion: special case min/max, until we get generic methods. I take it you were trying out --strong mode? if you're willing to give it another go, I can kick out a dev compiler release and roll it into SDK, would show up in next SDK dev build. Or you could try |
Awesome, thank you for the quick fix! ❤️ |
Right now, this code:
generates a warning:
It would be really nice if DDC could infer the tighter
int
return type if it knows the arguments are both ints. A "real" solution likely involves either generic methods:or maybe some kind of TypeScript-style overloading. In the absence of either of those, it could be worth special-casing
min
andmax
in the same way that the spec does for the arithmetic operators.The text was updated successfully, but these errors were encountered: