americium icon indicating copy to clipboard operation
americium copied to clipboard

Trials.reject should be compatible with any type.

Open sageserpent-open opened this issue 2 years ago • 1 comments

Trials.reject currently is typed to yield Unit in Scala and void in Java. This means that it can't be used in a value expression, so it tends to end up either in a guard block or is hoisted right up to a catch clause of a try construct that encloses the entire parameterised test.

It would be nice to make it more like Scala's ??? operator, so it can be used anywhere, safe in the knowledge that it always throw an exception and is thus nominally compatible with any expected type.

Not sure what the equivalent in Java would be - maybe define it as a generic method and hope that type inference will be able to unify at its call sites?

sageserpent-open avatar Dec 01 '23 12:12 sageserpent-open

JUnit5's Assertions.fail uses the generic approach and that seems to work nicely, so that's what we'll do for the Java flavour.

sageserpent-open avatar Dec 01 '23 12:12 sageserpent-open