simolus3 / drift

Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
https://drift.simonbinder.eu/
MIT License
2.66k stars 372 forks source link

Type inference when using CAST on NULL in a UNION #3351

Closed frankvollebregt closed 5 hours ago

frankvollebregt commented 7 hours ago

Describe the bug I might have created a bit of an edge case I think ;)

In my code, I am using a statement like this:

-- after generation, value is an int?
SELECT CAST(NULL AS INT) AS value;

Which, as expected, results in value being an int? equal to null. If I fill it with a value that is guaranteed to be non-null, it becomes an int, also in line with expectations.

But once I use a UNION, things get a bit unexpected:

-- after generation, value is an int
SELECT CAST(NULL AS INT) AS value

UNION

SELECT CAST(NULL AS INT);

Now, the type of value is int, and Drift believes it can no longer be null.

simolus3 commented 5 hours ago

Nice catch!