-
Notifications
You must be signed in to change notification settings - Fork 637
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
Should throw should allow for assignments to throw exceptions #387
Comments
Ok so the issue is that an assignment is not an expression, and the shouldThrow excepts a function that returns a value. We can change the shouldThrow definition to say the function returns a unit, but then you get warnings if your function does return a value. I'm not sure if it's possible to get both to work, if not, I would have to add another function like shouldThrowUnit for use cases above. What do you think ? |
A workaround, current is to do something like
I'm cooking a Pull Request for this: I also put this in discussion in jetbrains youtrack: |
The only problem in my branch right now is that you can't have both the functions in the same class. We'll have to put them in another namespace, as they're considered the same in this class, but it might work |
The function would have to be called shouldThrowUnit { } so that it has a different name. Not elegant but would work. |
It's not a problem to have the same name, they just must be in different namespaces |
Is that more confusing or less? If you tried to use both in the same file, one would just not compile, and you'd have to know to manually add another import ? |
And one can be an overload of the other. For example, I created the workaround in my application:
This can be in kotlintest too, but must be in different packages. I'm not usre if it's less elegant than |
That may be more confusing, indeed |
Both are not ideal, perhaps there's a trick one can do that one of the Jetbrains team knows about @udalov |
In the end I've added |
I expect this syntax to be possible, as the assignment throws an exception:
The text was updated successfully, but these errors were encountered: