hyperjumptech / grule-rule-engine

Rule engine implementation in Golang
Other
2.16k stars 338 forks source link

Modulo panicking #454

Open Omnia89 opened 1 month ago

Omnia89 commented 1 month ago

Describe the bug I've tried to use the modulo operator, either like an operator and the function, but it keeps giving me error on execution. I'm using the JSON format of the rule.

The object given is a JSON, and I've tried to give both {"Lengh": 10} and {"Lengh": 10.0}

The rule is:

--- Function version 
[
    {
        "name": "Test",
        "salience": 10,
        "then": [
            {
                "set": [
                    "Item.Price",
                    {
                        "call": [
                            "ItemFunc.PriceMultiply",
                            {
                                "obj": "Item.Price"
                            },
                            {
                                "const": 0.9
                            }
                        ]
                    }
                ]
            },
            {
                "call": [
                    "Retract",
                    {
                        "const": "Test"
                    }
                ]
            }
        ],
        "when": {
            "eq": [
                {
                    "call": [
                        "Mod",
                        {
                            "obj": "Item.Length"
                        },
                        {
                            "const": 10
                        }
                    ]
                },
                {
                    "const": 0
                }
            ]
        }
    }
]
--- Operation version
...
        "eq": [
                     {
                         "mod": [
                             {
                                 "obj": "Item.Length"
                             },
                             {
                                 "const": 10
                             }
                         ]
                     },
                     {
                         "const": 0
                     }
          ]
...

In the first one, the error says that I cannot use int64 for float64 args. In the second one that I cannot use float64 for int64 args.

Expected behavior To do the modulo operation

Additional context github.com/hyperjumptech/grule-rule-engine v1.10.5 go 1.16