GQL
GQL copied to clipboard
Incorrect expr_type for ArithmeticExpression
Describe the bug
Incorrect expr_type for ArithmeticExpression
To Reproduce
// https://github.com/AmrDeveloper/GQL/blob/master/crates/gitql-ast/src/expression.rs
let express = ArithmeticExpression {
left: Box::new(NumberExpression {
value: Value::Integer(1),
}),
operator: ArithmeticOperator::Plus,
right: Box::new(NumberExpression {
value: Value::Float(1.0),
}),
};
let scope = Enviroment {
globals: Default::default(),
globals_types: Default::default(),
scopes: Default::default(),
};
let ret = express.expr_type(&scope);
assert_eq!(ret.is_float(), true); // fails
Expected behavior
assert_eq!(ret.is_float(), true); // ret is true
GQL (please complete the following information):
Version 0.11.0
Screenshots
See: https://github.com/AmrDeveloper/GQL/blob/master/crates/gitql-ast/src/expression.rs
Incorrect
fn expr_type(&self, scope: &Environment) -> DataType {
let lhs = self.left.expr_type(scope);
let rhs = self.left.expr_type(scope);
if lhs.is_int() && rhs.is_int() {
return DataType::Integer;
}
DataType::Float
}
Correct
let lhs = self.left.expr_type(scope);
let rhs = self.right.expr_type(scope);
Hello @craftslab,
Thank you for reporting it, i fixed it now
Thank you
Fixed and released on 0.12.0