Fix issue where cast confuses type inference #329
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a potential compilation issue that appears in certain edge cases where the explicit typecast during SQL generation somehow confuses the type inference.
This does not seem to be a frequent issue as it only ever happened to me in one occasion where I had two models without date / timestamp columns (the following are abstractions of those)
which are connected via a many-to-many relation (with one-sided access).
When calling
sample.remove_others(other)
, this leads to a corresponding compilation error as the type inference algorithm seems to believe that the cast injennifer.cr/src/jennifer/adapter/postgres/sql_generator.cr
Lines 123 to 130 in 7042ffd
more specifically
jennifer.cr/src/jennifer/adapter/postgres/sql_generator.cr
Line 126 in 7042ffd
is invalid.
The error is then as follows:
Appendix
Since this seems to be also a bug in the compiler / type inference algorithm, it would probably worth it to also post it there. I wanted to push this here first, as it is easy to fix for this simple case - please let me know what you think about that.