I wonder if Kotlin might now or in the future have the language support to be able to do something like the handy "power assertion" feature as seen in Groovy.
This really is a nice feature of Groovy! But I suppose being that concise would only be possible with access to the syntax tree. I don't see any way for a custom assert statement to get a hold of the original expression 91 == a * b. An alternative would be a assert keyword with those capabilites that is part of the Kotlin language.
Which assert doesn’t work in production? Are you saying you want an assert that’s always enabled, and doesn’t require runtime assertions to be turned on for the JVM? (Currently, the assertion functions in kotlin.test fit that bill, and I can’t think of a reason not to use them in production code.)
sometimes we have define the option type such as “var a: ClassA? = null” ,and then i need check a :
val realA = a?:return
if(realA.somePr == true){
//do …
}
//…
.but i want to use it like swift :
guard let realA = a else {
return
}
if(realA.somePr == true){
//do …
}
//…
how to impl it?
@pniederw1 have you seen the kotlin compiler plugin architecture? Saw a talk about this at KotlinConf 2018 and the first thing that came to mind was “OMG this could make Spock stuff possible” (big fan :D)
This was the talk:
I was just starting to look into the feasibility of it, poking around thinking of power assertions and parameterised tests, since I miss those greatly. I see this was a while back, so wondering if you are still considering something towards this?