robfletcher
02/01/2022, 4:07 PMchristophsturm
02/01/2022, 4:37 PMEric
02/01/2022, 4:38 PMisNotNull
christophsturm
02/01/2022, 5:28 PMrobfletcher
02/01/2022, 6:02 PM<T : Any?>
then it's impossible to define that it returns an assertion enclosing a definitely non-null subjectfun <T : Any> Assertion.Builder<T?>.isNotNull(): Assertion.Builder<T>
isNotNull
on a known non-null subject is not something I'd actually do, but I was happy to merge because it seemed at least harmlesschristophsturm
02/01/2022, 6:28 PMrobfletcher
02/01/2022, 6:32 PMchristophsturm
02/01/2022, 7:00 PMRoukanken
02/01/2022, 9:08 PMBuilder<T>.isNotNull()
- if you're doing any generics (weird in tests, but probably can happen in complex projects?) then stuff can get confusing
fun <T> test(subject: T) {
expectThat(subject).isNotNull()
}
fun main() {
test<Int?>(null)
}
afaik this will pass currently
I guess it won't happen that often in strikt, as you would rather write a custom assertion, and then this won't happen as much I think, but if you need to do something like communicate interactively a with some generic payload, stuff can get iffy...
(eg, do asserts in middle of communication of the payload and so, over different message types, maybe even collection types...)robfletcher
02/01/2022, 9:31 PMchristophsturm
02/02/2022, 8:41 AMrobfletcher
02/02/2022, 4:21 PM<T : Any?>
and the receiver is Assertion.Builder<T?>
which means the type could be say String?
and then the receiver is Assertion.Builder<String??>
Roukanken
02/02/2022, 4:24 PMfun <X> test()
and since Builder<T?>.isNotNull()
can't handle both cases X = Int
and X = Int?
it statically chooses Builder<T>.isNotNull()
and uses it always
Edit: use different generics to make it more readableBuilder<T>.isNotNull()
callable only non nullable T's, as it thinks it is (mostly, true but sometimes not) - eg, change signature to fun <T: Any> Builder<T>.isNotNull(): Builder<T>
• afaik, this would completely forbit usage of it in the case I described
b) give the Builder<T>.isNotNull()
same implementation as the other one, as it can happen it can get called on nullable T's, in special cases.
this ofc doesn't resolve the issue with T!
's...christophsturm
02/02/2022, 4:42 PMrobfletcher
02/03/2022, 12:46 AMchristophsturm
02/03/2022, 7:53 AMrobfletcher
02/03/2022, 2:47 PMisNotNull
narrows the subject type from T?
to T
and I don't see a way to do that while allowing for a non-null subject going inchristophsturm
02/03/2022, 2:49 PMrobfletcher
02/03/2022, 2:52 PMRoukanken
02/03/2022, 3:25 PMexpectThat(x) {
isNotNull().somethingOnlyOnNonNullable()
somethingOnlyOnNonNullable()
}
if first works because contracts, then the second has to work too (which it obviously can't)this@expectThat
and isNotNull()
)dave08
02/07/2022, 4:02 AMisNotNull {.... }