Can shouldBeInstanceOf some how utilise kotlin contracts?
See original GitHub issueI am not sure if this is possible 🤔
actualResponse shouldBeInstanceOf DomainResponse.Success::class.java
// can we use Kotlin contracts to say that this is indeed the instance of above type, so
// type would be inferred and no manual casting would be needed latter?
actualResponse
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Kotlin Contracts | Baeldung on Kotlin
We can only apply contracts on top-level functions with a body, i.e. we can't use them on fields and class functions. The contract...
Read more >What Are Kotlin Contracts and How Are They Useful?
The main purpose of contracts is to help the Kotlin compiler with complicated code analysis in cases where the developer knows more details...
Read more >are there plans to leverage contracts i find i do something | Kotlintest ...
I closed the issue. I don't think this is possible with the current contracts.
Read more >io.kotlintest.matchers.types.matchers.kt Maven / Gradle / Ivy
ExperimentalContracts import kotlin.contracts.contract /** * Verifies that this ... of [shouldBeInstanceOf] * * For an exact type, use [shouldNotBeTypeOf] ...
Read more >Understanding Kotlin contracts - Kt. Academy
Since Kotlin 1.3 we can enjoy new, mysterious feature — Kotlin contracts. ... They were there to state some requirements that couldn't be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Let me ask about this again - could we get support for contracts instead of having to use the returned value? Would make code slimmer in a bunch of cases.
I’d be happy to open the PR for this 😃
To be precise. Current implementation solves this problem by using value assign (it’s fine) instead of type inference (would be better).