Let's say I have a setup like so:
abstract class FooTest {
open lateinit var softAssertions: SoftAssertions
... reusable auxiliary functions ...
}
@ExtendWith(SoftAssertionsExtension::class)
class BarTest: FooTest(){
@InjectSoftAssertions
override lateinit var softAssertions: SoftAssertions
... actual test cases ...
}
IntelliJ gives me a very helpful warning for softAssertions
in BarTest
:
lateinit var overrides lateinit var
Yeeeeeeees ..? Go on, what's your point?
I eventually realised that my lateinit var
in FooTest
really should be an abstract val
, instead - which got rid of the warning - but even so, I'm wondering ... is there something about a lateinit var
overriding a lateinit var
that I should know but don't and IntelliJ wants to tell me but doesn't?
The reason is described in the issue which added the inspection:
These two different backing fields also can lead to fun things like 'isInitialized' property of a lateinit variable is false when it is overridden as a var by another class.
It could make sense to add an exception where overriding property has an annotation like in your case.