Has anyone been able to try the new Explanation/Ex...
# power-assert
b
Has anyone been able to try the new Explanation/Expression Power-Assert API with 2.4.0-Beta2? We want to stabilize the API in the next week for the 2.4.0-RC release, and I'm looking for any feedback people might have.
Biggest thing I'm considering right now is changing both Explanation and Expression from abstract classes with internal constructors to interfaces. This would allow libraries to implement their own if needed and allow for a little more flexibility in evolving the API. Let me know your thoughts!
r
Unfortunately I wasn't able to try it out yet for Atrium, too busy currently. I think using interfaces instead of abstract classes would be better (would example allow to provide CallExplanations in another way than via power-assert). Did I understand it correctly, will
@PowerAssert
be part of the stdlib in 2.4.0-RC or do I still need an extra dependency?
The
explanation
property will return
null
in cases when a
@PowerAssert
annotated function is called without call-site information, including:
• The call-site was compiled without the compiler plugin applied.
• When called from non-Kotlin code. For example, Java.
• When called via reflection or method reference.
Could you please use something like
Result<CallExplanation>?
for
explanation
. I would like be able to distinguish between: the user has not applied the compiler plugin (in which case I can give a hint to the user) vs. the information is not available because of Java/reflection Regarding method reference, say I have
foo
with
@PowerAssert
which takes
T
Copy code
foo(::bla)
will explanation now not even contain
::bla
?
b
Did I understand it correctly, will
@PowerAssert
be part of the stdlib in 2.4.0-RC or do I still need an extra dependency?
No, it will still be an extra dependency. But this dependency will be provided automatically by the Power-Assert Gradle plugin, so for most users, no additional configuration should be required. Libraries may need to adjust what source sets are targeted by the Gradle plugin so main compilations are included, but then the dependency will be added to those compilations as well.
Could you please use something like
Result<CallExplanation>?
for
explanation
. I would like be able to distinguish between: the user has not applied the compiler plugin (in which case I can give a hint to the user) vs. the information is not available because of Java/reflection
Unfortunately, it is not possible to distinguish between these cases. Because it's a compiler plugin, it's either applied or its not. There's no way to know the call was made from a context where the compiler plugin could have been applied. In the future - as we move power-assert into the language proper - we will be able to warn about this. But that is still a long ways off.
[...] will explanation now not even contain
::bla
?
If it doesn't, this would be considered a bug.