AmrDeveloper / GQL

Git Query language is a SQL like language to perform queries on .git files with supports of most of SQL features such as grouping, ordering and aggregations functions
https://amrdeveloper.github.io/GQL/
MIT License
3.3k stars 90 forks source link

Incorrect expr_type for ArithmeticExpression #72

Closed craftslab closed 10 months ago

craftslab commented 10 months ago

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

expression.rs
craftslab commented 10 months ago

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);
AmrDeveloper commented 10 months ago

Hello @craftslab,

Thank you for reporting it, i fixed it now

Thank you

AmrDeveloper commented 10 months ago

Fixed and released on 0.12.0