Resolve type of EXISTS expressions in types2 (#874)

This commit is contained in:
Simon Binder 2020-10-16 12:31:18 +02:00
parent a4df55029c
commit 89e019f756
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 11 additions and 0 deletions

View File

@ -217,6 +217,12 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
visit(e.inner, _expectString);
}
@override
void visitExists(ExistsExpression e, TypeExpectation arg) {
session._checkAndResolve(e, const ResolvedType.bool(), arg);
visit(e.select, const NoTypeExpectation());
}
@override
void visitUnaryExpression(UnaryExpression e, TypeExpectation arg) {
final operatorType = e.operator.type;

View File

@ -192,6 +192,11 @@ void main() {
expect(type, const ResolvedType(type: BasicType.int));
});
test('infers type of EXISTS expressions', () {
final type = _resolveResultColumn('SELECT EXISTS(SELECT * FROM demo);');
expect(type, const ResolvedType.bool());
});
test('resolves subqueries', () {
final type = _resolveResultColumn('SELECT (SELECT COUNT(*) FROM demo);');
expect(type, const ResolvedType(type: BasicType.int));