Add test for type hints in between expressions

This commit is contained in:
Simon Binder 2020-09-06 13:27:30 +02:00
parent 70096357e0
commit fa432ee17a
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 22 additions and 0 deletions

View File

@ -263,6 +263,7 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
visitChildren(e, _expectNum);
session
.._checkAndResolve(e, const ResolvedType.bool(), arg)
.._addRelation(NullableIfSomeOtherIs(e, e.childNodes))
.._addRelation(HaveSameType(e.lower, e.upper))
.._addRelation(HaveSameType(e.check, e.lower));

View File

@ -233,6 +233,27 @@ WITH RECURSIVE
expect(type, const ResolvedType(type: BasicType.int));
});
test('resolves type hints from between expressions', () {
const dateTime = ResolvedType(type: BasicType.int, hint: IsDateTime());
final session = _obtainResolver(
'SELECT 1 WHERE :date BETWEEN :start AND :end',
options: const AnalyzeStatementOptions(
namedVariableTypes: {':date': dateTime},
),
).session;
Variable start, end;
for (final variable in session.context.root.allDescendants
.whereType<ColonNamedVariable>()) {
if (variable.name == ':start') start = variable;
if (variable.name == ':end') end = variable;
}
assert(start != null && end != null);
expect(session.typeOf(start), dateTime);
expect(session.typeOf(end), dateTime);
});
group('IS IN expressions', () {
test('infer the variable as an array type', () {
final type = _resolveFirstVariable('SELECT 3 IN ?');