hyperjumptech/grule-rule-engine

IsNil panics when passing in an untyped nil value

kevinkassimo opened this issue · 1 comments

Describe the bug
When calling GRuleEnvironment.ExecuteRule(...) with knowledge base that contains a null field and a rule that calls IsNil on this field, it prints that it panics. The recovered error message after stepping through the error shows reflect: Call using zero Value argument

To Reproduce
Steps to reproduce the behavior:

  1. Create a DataContext and call dataCtx.AddJSON("f", someJSON) where this JSON is { "nullable": null }
  2. Create a rule that says IsNil(f.nullable).
  3. Pass the rule and the knowledge based based on this data context and call ExecuteRule.

Seems that this happens during CallFunction which reflect will check for the inherent type of the value. Since nil by itself is untyped, it fails the the above error.

Expected behavior
IsNil should evaluate to true.

Additional context
Add any other context about the problem here.

Same issue happened to me today. I have used the nil literal as NIL in IsNil function by typing IsNil(NIL) just for test purposes, also the Fact.STH = NIL; line also raised panic for the same reason.