Remove lint around binary expr types

This commit is contained in:
Simon Binder 2022-05-10 20:46:30 +02:00
parent b7cbb31339
commit 5e3de2fb7c
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 0 additions and 79 deletions

View File

@ -29,54 +29,6 @@ class _LintingVisitor extends RecursiveVisitor<void, void> {
_LintingVisitor(this.linter);
@override
void visitBinaryExpression(BinaryExpression e, void arg) {
const numericOps = {
TokenType.plus,
TokenType.minus,
TokenType.star,
TokenType.slash,
};
const binaryOps = {
TokenType.shiftLeft,
TokenType.shiftRight,
TokenType.pipe,
TokenType.ampersand,
TokenType.percent,
};
final operator = e.operator.type;
void checkTypesFor(List<BasicType> allowed, String message) {
for (final child in e.childNodes) {
final type = linter.context.typeOf(child as Expression);
if (type.unknown) continue;
final basicType = type.type?.type;
if (basicType != null && !allowed.contains(basicType)) {
linter.lints.add(AnalysisError(
type: AnalysisErrorType.other,
message: message,
relevantNode: child,
));
}
}
}
if (numericOps.contains(operator)) {
checkTypesFor(
[BasicType.int, BasicType.real],
'Expression should be numeric, the resulting value might be unexpected',
);
}
if (binaryOps.contains(operator)) {
checkTypesFor(
[BasicType.int],
'Expression should be an int, the resulting value might be unexpected',
);
}
}
@override
void visitDriftSpecificNode(DriftSpecificNode e, void arg) {
if (e is DartPlaceholder) {

View File

@ -91,37 +91,6 @@ in: INSERT INTO foo (id) $placeholder;
);
});
group('warns about wrong types in subexpressions', () {
test('strings in arithmetic', () {
final result = engine.analyze("SELECT 'foo' + 3;");
final moorQuery = QueryHandler(result, mapper).handle(fakeQuery);
expect(
moorQuery.lints,
contains(isA<AnalysisError>().having(
(e) => e.message, 'message', contains('should be numeric'))),
);
});
test('allows numerics in arithmetic', () {
final result = engine.analyze('SELECT 3.6 * 3;');
final moorQuery = QueryHandler(result, mapper).handle(fakeQuery);
expect(moorQuery.lints, isEmpty);
});
test('real in binary', () {
final result = engine.analyze('SELECT 3.5 | 3;');
final moorQuery = QueryHandler(result, mapper).handle(fakeQuery);
expect(
moorQuery.lints,
contains(isA<AnalysisError>()
.having((e) => e.message, 'message', contains('should be an int'))),
);
});
});
test(
'warns when nested results appear in compound statements',
() async {