I'm trying to use kotlin contracts but I'm getting an unresolved reference when I build the project. the class I have looks like this:
Copy code
sealed class Foo {
fun isFooOne(): Boolean {
contract {
returns(true) implies (this@Foo is FooOne)
returns(false) implies (this@Foo is FooTwo)
}
return this is FooOne
}
data class FooOne(val valueOne: String) : Foo()
data class FooTwo(val valueTwo: String, val bar: String) : Foo()
}
This is defined in a share kotlin multiplatform project. I'm able to use this in another module(android project) like so:
Copy code
val foo = getFoo()
if (foo.isFooOne()) {
val fooValue = foo.valueOne
} else {
val fooBar = foo.bar
}
The ide doesn't give any error but when I build the project it say
foo.bar
is unresolved at
val fooBar = foo.bar
. Not sure what I'm missing here...any insight would be appreciated. Thanks