-
Notifications
You must be signed in to change notification settings - Fork 36
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
Merge raisesCondition()
into raises()
using EitherType
.
#127
Conversation
`EitherType` attempts to unify the left type first, so it will match `T` if possible, and default to `Any` if not. This only works when `type` comes before `condition`, and since both arguments are optional, it's possible the user will pass only the function, which will be incorrectly interpreted as being `type`, so we have to check for that. Arguably, the same can be said of `msgNotThrown`.
Previously, Haxe typed it as `haxe.Exception`, so couldn't assign other values to it on static targets. Shadowing the variable is the simplest way around this. And it should be declared above `checkCondition()`. Whoops.
Whoops, forgot static targets exist for a moment there! But it should all work now. Edit: nope, but it made progress at least. I'd like to reiterate that if we just changed |
JavaScript, where types are functions...
Ugh, it seems the trick with I see two viable options here:
|
Old versions of Haxe aren't good enough at type inference.
raisesCondition()
into raises()
.raisesCondition()
into raises()
using EitherType
.
I think instead of trying to hack the type system it's better to keep both methods for now. |
Is there a benefit to not adding the metadata immediately? |
Or do the solution I proposed in #128? That one doesn't "hack the type system" at all. I've explained why I think that's the better option, so maybe that ought to remain open and this should be closed. Edit: or I can do a third pull request with the new name, and these two can both be closed. |
Less distracting migration process for projects using utest. |
I discussed making a macro for this, and while that would handle a wider variety of cases more reliably, Assert.hx is already way too long, and I couldn't bring myself to make it so much longer.
Instead, I found a way to get type
T
from thetype
argument while also allowing the user to passAny
type.EitherType
attempts to unify the left type first, so it will matchT
if possible, and default toAny
if not.This only works when
type
comes beforecondition
, and since both arguments are optional, it's possible the user will pass only the function, which will be incorrectly interpreted as beingtype
, so we have to check for that. Arguably, the same can be said ofmsgNotThrown
.I still recommend changing
type
toClass<T>
as soon as possible, but until then, this is the next best thing.