question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can shouldBeInstanceOf some how utilise kotlin contracts?

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
zsmb13commented, Sep 7, 2021

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 😃

0reactions
igorwojdacommented, Mar 18, 2019

To be precise. Current implementation solves this problem by using value assign (it’s fine) instead of type inference (would be better).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found