-
In our codebase we have a Patcher that let's us not specify the context as a function value if the function requires a context. However when we compile scripts with the 1.15.4 version we get errors similar to: Embedded test:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 11 replies
-
+1 We have overriden the binary operators (&&, ||) in our code. For simple expression (Func1() || Func2()) it is working as expected, but when we introduce a complex(not so) expression (Func1() || Func2() || Func3()), it is erroring out.
|
Beta Was this translation helpful? Give feedback.
-
First about this issue. Before 1.15.4, You need to add opts := []expr.Option{
expr.AsFloat64(),
+ expr.AsAny(),
} More info in #347.
Without code, it is unclear. I maybe some bug in your Patcher implementation. Tr to dump ast after patching. |
Beta Was this translation helpful? Give feedback.
-
After a long debugging session I figured out that the checker.Check modifies the ast state by setting the nodeType. In my patcher I don't want my users to have to pass the context argument to the functions we call as that isn't ergonomic or necessary for the scripters to have to know if the function call requires an context argument or not. From my example above our users would input: So when the checker runs at https://github.com/antonmedv/expr/blob/939aca18e66514ca0727c309f8df8c510a0e2fc1/expr.go#L182C1-L182C8 The change to checker.CallNode introduced in fcf2b55 causes the issue I have. Maybe what I need is to have another visitor that runs before performing the typecheck to modify the AST for my usecase? |
Beta Was this translation helpful? Give feedback.
-
Any tips for fixing this error I slightly modified the operator overloading example (https://expr.medv.io/docs/Operator-Overloading) to overload || operator Tried SetType using patcher still did not help
response
|
Beta Was this translation helpful? Give feedback.
First about this issue. Before 1.15.4,
AsFloat64()
would acceptfloat64 || any
. Now it is more explicit, and accepts only float64.You need to add
AsAny()
:opts := []expr.Option{ expr.AsFloat64(), + expr.AsAny(), }
More info in #347.
Without code, it is unclear. I maybe some bug in your Patcher implementation. Tr to dump ast after patching.