Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: produced array may have side-effect to given args #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jizhuozhi
Copy link

In some condition that given args has an array, for example:

	functions := map[string]ExpressionFunction{
		"func1": func(args ...interface{}) (interface{}, error) {
			return args, nil
		},
	}
	exp, _ := NewEvaluableExpressionWithFunctions("func1(args, 1, 2, 3)", functions)
	result, _ := exp.Evaluate(map[string]interface{}{
		"args": []interface{}{1, 2, 3},
	})

In general programming languages, it excepts []interface{}{[]interface{}{1, 2, 3}, 1.0, 2.0, 3.0}, but actually, it will return []interface{}{1, 2, 3, 1.0, 2.0, 3.0} with side-effects and may cause data race when multi-threads executing even expression is stateless.

The root cause is separatorStage using contextless left production rule, so no way to check the slice type left value is produced by separatorStage or user given parameter. There is a simple to check is using type alias to change the etype of produced slice.

@jizhuozhi jizhuozhi changed the title fix: produced array may append to given args fix: produced array may have side-effect to given args Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant