-
Notifications
You must be signed in to change notification settings - Fork 697
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
fix: EXPOSED-266 Between() accepts arguments of different type than column type #1983
Conversation
…olumn type between() currently accepts arguments of types that do not match the type stored in the column on which it is called. In the event that this is being taken advantage of by users, rather than introducing an immediate breaking change, the upper bounds have been restricted to show a compiler warning. A function override has also been introduced to ensure that this warning does not show when invoked on an EntityID column with literal arguments.
…olumn type Replace deprecated datetime functions in tests.
fun <T, S : T?> ExpressionWithColumnType<S>.between(from: T, to: T): Between = Between(this, wrap(from), wrap(to)) | ||
fun <T, S : T?> ExpressionWithColumnType<in S>.between(from: T, to: T): Between = Between(this, wrap(from), wrap(to)) | ||
|
||
/** Returns `true` if this [EntityID] expression is between the values [from] and [to], `false` otherwise. */ | ||
fun <T : Comparable<T>, E : EntityID<T>?> ExpressionWithColumnType<E>.between(from: T, to: T): Between = Between(this, wrap(from), wrap(to)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above, I'm not sure how to test for the presence of a compiler warning as all existing tests use arguments with the correct type. And any test purposefully set up to show a warning would fail when we upgrade the Kotlin version.
Please let me know if there's any type of test that should be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine not to test it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
fun <T, S : T?> ExpressionWithColumnType<S>.between(from: T, to: T): Between = Between(this, wrap(from), wrap(to)) | ||
fun <T, S : T?> ExpressionWithColumnType<in S>.between(from: T, to: T): Between = Between(this, wrap(from), wrap(to)) | ||
|
||
/** Returns `true` if this [EntityID] expression is between the values [from] and [to], `false` otherwise. */ | ||
fun <T : Comparable<T>, E : EntityID<T>?> ExpressionWithColumnType<E>.between(from: T, to: T): Between = Between(this, wrap(from), wrap(to)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine not to test it
between()
currently accepts arguments of types that do not match the type stored in the column on which it is called.This means that the following is technically possible to compile:
In the event that this is being taken advantage of by users (for example with numeric or UUID types), rather than introducing an immediate breaking change, the upper bounds have been restricted to highlight the offending function and show a compiler warning.
A function overload has also been introduced to ensure that this warning does not show when invoked on an
EntityID
column with appropriate literal arguments.Note: No tests have been added and all tests for
between()
in the datetime modules provide matching argument types with no warnings.Additional: