Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

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

Open
jizhuozhi wants to merge 1 commit into
Knetic:masterfrom
jizhuozhi:master
Open

fix: produced array may have side-effect to given args#205
jizhuozhi wants to merge 1 commit into
Knetic:masterfrom
jizhuozhi:master

Conversation

@jizhuozhi

Copy link
Copy Markdown

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant