check you still need an explicit cast to ColumnGroup<*> to be able to call columnsCount() on myCol. The check should tell the compiler that it's actually a column group, similar to what an myCol is ColumnGroup<*> would do.
This is actually possible with Kotlin contracts:
@OptIn(ExperimentalContracts::class)
public fun AnyCol.isColumnGroup(): Boolean {
contract {
returns(true) implies (this@isColumnGroup is ColumnGroup<*>)
}
return kind() == ColumnKind.Group
}
makes
if (myCol.isColumnGroup()) {
myCol.columnsCount() // compile
} else {
myCol.columnsCount() // not compile
}
It's odd that after a
check you still need an explicit cast to
ColumnGroup<*>
to be able to callcolumnsCount()
onmyCol
. The check should tell the compiler that it's actually a column group, similar to what anmyCol is ColumnGroup<*>
would do.This is actually possible with Kotlin contracts:
makes
Unfortunately contracts aren't all-powerful (yet):