aviatorscript icon indicating copy to clipboard operation
aviatorscript copied to clipboard

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

Open wongshung opened this issue 1 year ago • 1 comments

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 avatar Sep 06 '24 07:09 wongshung

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

wongshung avatar Sep 06 '24 07:09 wongshung

预期行为,请明确判断一个变量是否是 nil,再使用。 或者启用 NIL_WHEN_PROPERTY_NOT_FOUND.

https://www.yuque.com/boyan-avfmj/aviatorscript/yr1oau#NIL_WHEN_PROPERTY_NOT_FOUND

killme2008 avatar Nov 20 '24 14:11 killme2008