expr icon indicating copy to clipboard operation
expr copied to clipboard

Patch/SetType relations

Open antonmedv opened this issue 2 years ago • 0 comments

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: TestMe("1.33").GetFloat() but the actual script that the patcher generates will be TestMe(ctx, "1.33").GetFloat()

So when the checker runs at https://github.com/antonmedv/expr/blob/939aca18e66514ca0727c309f8df8c510a0e2fc1/expr.go#L182C1-L182C8 it will set the return value of the TestMe function to the invalid value interface{} instead of the correct value *scripting.TestStruct as the script is syntactically correct but fails to the checker before we run the patcher.

The change to checker.CallNode introduced in https://github.com/antonmedv/expr/commit/fcf2b55decfdb74892e3f30e28c73f45cd24ec15 in combination with https://github.com/antonmedv/expr/blob/939aca18e66514ca0727c309f8df8c510a0e2fc1/checker/checker.go#L135

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?

Originally posted by @tw1nk in https://github.com/antonmedv/expr/discussions/473#discussioncomment-7643119

antonmedv avatar Nov 25 '23 15:11 antonmedv