Rego:设定理解未定义
我试图理解为什么以下有关使用设置理解的示例给出不同的结果:
- /a>
在第一个示例中,尽管foo [“ c”]
未定义,rlt
仍将其评估为空集。我希望rlt
也会不确定。
在第二个示例中,我删除了该函数,但直接将rlt2
设置为设置理解的结果。这次它确实返回了未定义。
有人可以在这里解释区别吗?
I am trying to understand why the following examples on using set comprehension give different results:
In the first example, rlt
is evaluated to an empty set despite foo["c"]
is undefined. I expect rlt
to also be undefined.
In the second example, I removed the function but directly set rlt2
to the result of a set comprehension. This time it does return undefined.
Can someone explain the difference here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您在这里看到的是类型的检查器,尽其所能。
您遇到的错误是因为在编译时,类型检查器知道存在哪些键。
对于函数调用,
foo
是一个函数参数,编译器无法分辨
foo [“ c”]
是否存在或不存在 - 这取决于实际调用。您可能会这样定义该函数,但是以其他方式使用它,因此它不会进行任何更深的流分析。
现在,
rlt
不是不确定的,因为设置(对象,数组)综合永远不会不确定 - 如果它们的身体始终不确定,则整个集合将变为空集(对象,数组)。I think what you see here is the type checker doing the best it can.
The error you get, is because at compile time, the type checker knows which keys exist.
For the function call,
foo
is a function argument,and the compiler cannot tell if
foo["c"]
exists or does not exist -- that depends on the actual call. You might define the function like that, but use it in other ways likeSo it doesn't do any kind of deeper flow analysis.
Now
rlt
is not undefined because set (object, array) comprehensions are never undefined -- if their bodies are always undefined, the overall collection becomes an empty set (object, array).