Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nullability matchers with Kotlin Contracts #602

Merged

Conversation

LeoColman
Copy link
Member

With Kotlin Contracts it's possible to establish that "If this function passes, X is true". This commit implements nullability type matchers for the Any? type, using Contracts to allow non-null inference to users.

This commit didn't implement the same logic for matchers such as x.shouldBeInstanceOf<Foo>(), because currently it's impossible to implement this with Kotlin Contracts. https://youtrack.jetbrains.com/issue/KT-28298

Fixes #601

@LeoColman LeoColman requested a review from sksamuel January 21, 2019 14:27
@LeoColman
Copy link
Member Author

@dave08
Take a look.
Special attention to the part that states shouldBeInstanceOf doesn't allow for Contracts to be used

@dave08
Copy link
Contributor

dave08 commented Jan 21, 2019

You might want to add another assertion after the shouldNotBeNull() that uses the non-null value so that if there are breaking changes to contracts, the tests will fail?

@LeoColman LeoColman force-pushed the feature/601-kotlin-contracts-for-type-inference branch from c669001 to af3620f Compare January 21, 2019 15:46
With Kotlin Contracts it's possible to establish that "If this function passes, X is true". This commit implements nullability type matchers for the `Any?` type, using Contracts to allow non-null inference to users.

This commit didn't implement the same logic for matchers such as `x.shouldBeInstanceOf<Foo>()`, because currently it's impossible to implement this with Kotlin Contracts. https://youtrack.jetbrains.com/issue/KT-28298

Fixes #601
@LeoColman
Copy link
Member Author

Done

@sksamuel
Copy link
Member

3.3 only.

@LeoColman LeoColman changed the base branch from master to release/3.3.0 January 21, 2019 18:37
@LeoColman LeoColman merged commit b8b9a0a into release/3.3.0 Jan 21, 2019
@LeoColman LeoColman deleted the feature/601-kotlin-contracts-for-type-inference branch January 21, 2019 18:37
LeoColman added a commit that referenced this pull request Feb 11, 2019
With Kotlin Contracts it's possible to establish that "If this function passes, X is true". This commit implements nullability type matchers for the `Any?` type, using Contracts to allow non-null inference to users.

This commit didn't implement the same logic for matchers such as `x.shouldBeInstanceOf<Foo>()`, because currently it's impossible to implement this with Kotlin Contracts. https://youtrack.jetbrains.com/issue/KT-28298

Fixes #601
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants