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

Capture variables from env for closure should be immutable #101

Closed
killme2008 opened this issue Jan 10, 2019 · 2 comments
Closed

Capture variables from env for closure should be immutable #101

killme2008 opened this issue Jan 10, 2019 · 2 comments
Labels

Comments

@killme2008
Copy link
Owner

For example

  String exp = "a=1; b = lambda(x) -> a+ x end ; a=4 ; b(5)";
    System.out.println(AviatorEvaluator.execute(exp)); // output 6

should output 6, but now is 9.

@killme2008 killme2008 added the bug label Jan 10, 2019
@killme2008 killme2008 changed the title Capature variables from env for closure should be immutable Capture variables from env for closure should be immutable Jan 10, 2019
@killme2008
Copy link
Owner Author

Now it will throw an exception for such assigment:

Exception in thread "main" com.googlecode.aviator.exception.ExpressionRuntimeException: Can't assignment value to captured variable.The `a` is already captured by lambda.
	at com.googlecode.aviator.utils.Env.put(Env.java:217)
	at com.googlecode.aviator.utils.Env.put(Env.java:1)
	at com.googlecode.aviator.runtime.type.AviatorJavaType.setValue(AviatorJavaType.java:264)
	at Script_1547125754122_0/1344622638.execute0(Unknown Source)
	at com.googlecode.aviator.ClassExpression.execute(ClassExpression.java:71)
	at com.googlecode.aviator.AviatorEvaluatorInstance.execute(AviatorEvaluatorInstance.java:741)
	at com.googlecode.aviator.AviatorEvaluator.execute(AviatorEvaluator.java:439)
	at com.googlecode.aviator.AviatorEvaluator.execute(AviatorEvaluator.java:451)
	at com.googlecode.aviator.AviatorEvaluator.execute(AviatorEvaluator.java:472)
	at com.googlecode.aviator.example.LambdaExample.main(LambdaExample.java:12)

@killme2008
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant