Skip to content

Conversation

jesyspa
Copy link

@jesyspa jesyspa commented Nov 10, 2023

The contract for processTupleArgument is meant to say that the function will not return a non-null value if nullIfNotFound = false. However, the old contract said the opposite: that if the function returned a non-null value, then nullIfNotFound = false, which is not true (if the value is found, nullIfNotFound plays no role).

At the moment, the compiler cannot use either contract meaningfully so the difference is immaterial. If https://youtrack.jetbrains.com/issue/KT-63378/Support-or-prohibit-contracts-that-use-Boolean-parameters-on-the-right-of-an-implies is resolved and support for this is added, the new contract will allow the call-sites that pass nullIfNotFound = false to perform a smart cast to List<R> instead of having to use !!.

The contract for `processTupleArgument` is meant to say that the
function will not return a non-null value if `nullIfNotFound = false`.
However, the old contract said the opposite: that if the function
returned a non-null value, then `nullIfNotFound = false`, which is not
true (if the value is found, `nullIfNotFound` plays no role).

At the moment, the compiler cannot use either contract meaningfully so
the difference is immaterial.  If https://youtrack.jetbrains.com/issue/KT-63378/Support-or-prohibit-contracts-that-use-Boolean-parameters-on-the-right-of-an-implies
is resolved and support for this is added, the new contract will allow
the call-sites that pass `nullIfNotFound = false` to perform a smart
cast to `List<R>` instead of having to use `!!`.
@piotrtomiak
Copy link
Contributor

Sorry for not getting back earlier, but this PR has slipped our attention. I've checked the mentioned issue and apparently in Kotlin 2.3 there is going to be support for Boolean.implies(v: ReturnsNotNull). So the proper contract definition will be:

contract {
  (!nullIfNotFound) implies (returnsNotNull())
}

I will leave this PR open till Angular plugin codebase is moved to Kotlin 2.3

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.

2 participants