Skip to content
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 Class<T>. #128

Closed
wants to merge 7 commits into from

Conversation

player-03
Copy link
Contributor

Previously, Assert.raises() took parameter type:Any, but I've changed it to type:Class<T>. In theory this is a breaking change, but I argue that it almost certainly won't break any code in practice because there was no use case for passing anything other than a Class. type gets passed to Std.isOfType(), so if it was anything other than a Class, the assertion would always fail, prompting the user to fix the error. Now, the prompt will happen at compile time rather than runtime.

This pull request is an alternative to #127. The two are similar, but this one is shorter, requires less documentation, and works in more versions of Haxe.

`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.
JavaScript, where types are functions...
Now Haxe will be able to correctly interpret each argument, so we don't have to check `isFunction()`, so JS will work again.
@player-03 player-03 changed the title Merge raisesCondition into raises using Class<T>. Merge raisesCondition() into raises() using Class<T>. Dec 16, 2023
@RealyUniqueName
Copy link
Member

Closing this to keep the discussion in one place: #127

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants