killme2008 / aviatorscript

A high performance scripting language hosted on the JVM.
http://fnil.net/aviator/
4.53k stars 841 forks source link

判断和使用不在env中的变量,若变量名带点号,判断nil时会直接报错 #643

Open wongshung opened 2 months ago

wongshung commented 2 months ago

Java代码大体如下: String expression = "return a==nil ? \"nothing\" : \"something\";"; Expression compiledExp = AviatorEvaluator.compile(expression, true); Map<String, Object> envMap = ImmutableMap.of("a", 1); Object result = compiledExp.execute(envMap);

此时可以正确返回“something”, 若expression换成"return $src==nil ? \"nothing\" : \"something\";",此时$src不在envMap里面,引擎还可以正确返回“nothing”, 若expression换成"return $src.pos==nil ? \"nothing\" : \"something\";",变量$src.pos不在envMap里面,期望也是返回“nothing”,但实际运行时直接报错了,报变量不存在。

是否是有什么限制?还是说是个bug?

wongshung commented 2 months ago

https://github.com/killme2008/aviatorscript/issues/496,有点类似之前的这个问题