Fix `CAST` always being non-nullable

This commit is contained in:
Simon Binder 2023-01-06 21:14:24 +01:00
parent d9072d7fac
commit 4b83810a17
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 5 additions and 1 deletions

View File

@ -434,7 +434,7 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
@override
void visitCastExpression(CastExpression e, TypeExpectation arg) {
final type = session.context.schemaSupport.resolveColumnType(e.typeName);
session._checkAndResolve(e, type, arg);
session._checkAndResolve(e, type.withoutNullabilityInfo, arg);
session._addRelation(NullableIfSomeOtherIs(e, [e.operand]));
visit(e.operand, const NoTypeExpectation());
}

View File

@ -58,6 +58,10 @@ const Map<String, ResolvedType?> _types = {
ResolvedType(type: BasicType.int, nullable: true, hint: IsDateTime()),
"SELECT datetime('now') = ?":
ResolvedType(type: BasicType.text, nullable: true, hint: IsDateTime()),
'SELECT CAST(NULLIF(1, 2) AS INTEGER) = ?': ResolvedType(
type: BasicType.int,
nullable: true,
),
};
SqlEngine _spawnEngine() {