mirror of https://github.com/AMT-Cheif/drift.git
Don't crash when trying to resolve variables
This commit is contained in:
parent
ae91b5d526
commit
ffe4bb8c82
|
@ -125,9 +125,8 @@ class TypeResolver {
|
||||||
if (_comparisonOperators.contains(operator)) {
|
if (_comparisonOperators.contains(operator)) {
|
||||||
return const ResolveResult(ResolvedType.bool());
|
return const ResolveResult(ResolvedType.bool());
|
||||||
} else {
|
} else {
|
||||||
final type = _encapsulate(expr.childNodes.cast(),
|
return _encapsulate(expr.childNodes.cast(),
|
||||||
[BasicType.int, BasicType.real, BasicType.text, BasicType.blob]);
|
[BasicType.int, BasicType.real, BasicType.text, BasicType.blob]);
|
||||||
return ResolveResult(type);
|
|
||||||
}
|
}
|
||||||
} else if (expr is CaseExpression) {
|
} else if (expr is CaseExpression) {
|
||||||
return resolveExpression(expr.whens.first.then);
|
return resolveExpression(expr.whens.first.then);
|
||||||
|
@ -141,7 +140,7 @@ class TypeResolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw StateError('Unknown expression $expr');
|
return const ResolveResult.unknown();
|
||||||
}, expr);
|
}, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,8 +264,8 @@ class TypeResolver {
|
||||||
return justResolve(parameters.first);
|
return justResolve(parameters.first);
|
||||||
case 'coalesce':
|
case 'coalesce':
|
||||||
case 'ifnull':
|
case 'ifnull':
|
||||||
return ResolveResult(_encapsulate(parameters,
|
return _encapsulate(parameters,
|
||||||
[BasicType.int, BasicType.real, BasicType.text, BasicType.blob]));
|
[BasicType.int, BasicType.real, BasicType.text, BasicType.blob]);
|
||||||
case 'nullif':
|
case 'nullif':
|
||||||
return justResolve(parameters.first).withNullable(true);
|
return justResolve(parameters.first).withNullable(true);
|
||||||
case 'first_value':
|
case 'first_value':
|
||||||
|
@ -276,19 +275,19 @@ class TypeResolver {
|
||||||
case 'nth_value':
|
case 'nth_value':
|
||||||
return justResolve(parameters.first);
|
return justResolve(parameters.first);
|
||||||
case 'max':
|
case 'max':
|
||||||
return ResolveResult(_encapsulate(parameters, [
|
return _encapsulate(parameters, [
|
||||||
BasicType.int,
|
BasicType.int,
|
||||||
BasicType.real,
|
BasicType.real,
|
||||||
BasicType.text,
|
BasicType.text,
|
||||||
BasicType.blob
|
BasicType.blob
|
||||||
])).withNullable(true);
|
]).withNullable(true);
|
||||||
case 'min':
|
case 'min':
|
||||||
return ResolveResult(_encapsulate(parameters, [
|
return _encapsulate(parameters, [
|
||||||
BasicType.blob,
|
BasicType.blob,
|
||||||
BasicType.text,
|
BasicType.text,
|
||||||
BasicType.int,
|
BasicType.int,
|
||||||
BasicType.real
|
BasicType.real
|
||||||
])).withNullable(true);
|
]).withNullable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.enableJson1) {
|
if (options.enableJson1) {
|
||||||
|
@ -431,15 +430,18 @@ class TypeResolver {
|
||||||
|
|
||||||
/// Returns the type of an expression in [expressions] that has the highest
|
/// Returns the type of an expression in [expressions] that has the highest
|
||||||
/// order in [types].
|
/// order in [types].
|
||||||
ResolvedType _encapsulate(
|
ResolveResult _encapsulate(
|
||||||
Iterable<Typeable> expressions, List<BasicType> types) {
|
Iterable<Typeable> expressions, List<BasicType> types) {
|
||||||
final argTypes = expressions
|
final argTypes = expressions
|
||||||
.map((expr) => justResolve(expr).type)
|
.map((expr) => justResolve(expr).type)
|
||||||
.where((t) => t != null);
|
.where((t) => t != null);
|
||||||
final type = types.lastWhere((t) => argTypes.any((arg) => arg.type == t));
|
final type = types.lastWhere((t) => argTypes.any((arg) => arg.type == t),
|
||||||
|
orElse: () => null);
|
||||||
|
if (type == null) return const ResolveResult.unknown();
|
||||||
|
|
||||||
final notNull = argTypes.any((t) => !t.nullable);
|
final notNull = argTypes.any((t) => !t.nullable);
|
||||||
|
|
||||||
return ResolvedType(type: type, nullable: !notNull);
|
return ResolveResult(ResolvedType(type: type, nullable: !notNull));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ Map<String, ResolveResult> _types = {
|
||||||
ResolvedType(type: BasicType.int, hint: IsDateTime())),
|
ResolvedType(type: BasicType.int, hint: IsDateTime())),
|
||||||
'SELECT row_number() OVER (RANGE ? PRECEDING)':
|
'SELECT row_number() OVER (RANGE ? PRECEDING)':
|
||||||
const ResolveResult(ResolvedType(type: BasicType.int)),
|
const ResolveResult(ResolvedType(type: BasicType.int)),
|
||||||
|
'SELECT ?;': const ResolveResult.unknown(),
|
||||||
};
|
};
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
Loading…
Reference in New Issue