Fix _encapsulate nullability for null literals

This commit is contained in:
Simon Binder 2021-07-26 18:56:22 +02:00
parent aa75cbaa19
commit 3bf91ed6c3
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 16 additions and 1 deletions

View File

@ -160,7 +160,7 @@ class TypeGraph {
if (previousType == elementType || elementType == BasicType.nullType) {
return previous.withNullable(eitherNullable);
}
if (previousType == BasicType.nullType) return element;
if (previousType == BasicType.nullType) return element.withNullable(true);
bool isIntOrNumeric(BasicType? type) {
return type == BasicType.int || type == BasicType.real;

View File

@ -212,6 +212,21 @@ void main() {
expect(type, const ResolvedType.bool());
});
test('supports unions', () {
void check(String sql) {
final resolver = _obtainResolver(sql);
final column = (resolver.session.context.root as CompoundSelectStatement)
.resolvedColumns!
.single;
final type = resolver.session.typeOf(column)!;
expect(type.type, BasicType.text);
expect(type.nullable, isTrue);
}
check("SELECT 'foo' AS r UNION ALL SELECT NULL AS r");
check("SELECT NULL AS r UNION ALL SELECT 'foo' AS r");
});
test('handles recursive CTEs', () {
final type = _resolveResultColumn('''
WITH RECURSIVE