Repository navigation
fix: surface Unknown for deep partial-eval patterns with missing ancestors #194
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
base: main
Are you sure you want to change the base?
Changes from all commits
76008e9
dfdbd5f
f7300ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -690,7 +690,16 @@ | |
| && (Boolean.TRUE.equals(value) || a instanceof OptionalValue) | ||
| ? OptionalValue.of(override) | ||
| : override; | ||
| if (a == PartialState.MISSING) throw missingAttribute(parent); | ||
| if (a == PartialState.MISSING) { | ||
| // Mirror the SELECT hop: a deep unknown pattern intersecting this read path produces an | ||
| // Unknown instead of a hard UNDECLARED error so resolve-and-retry can make progress. | ||
| // `attributeIntersect` only ever returns NONE or an Unknown, so the optional-lifting form | ||
| // used for `override` above is not needed here. | ||
| Object intersect = ctx.attributeIntersect(path); | ||
| if (intersect != PartialState.NONE) yield intersect; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reference equality is intentional here: |
||
| if (b instanceof Unknown u) yield u; | ||
| throw missingAttribute(parent); | ||
| } | ||
| if (a instanceof Unknown u) yield b instanceof Unknown v ? u.merge(v) : u; | ||
| if (b instanceof Unknown u) yield u; | ||
| if (error != null) throw error; | ||
|
|
@@ -706,6 +715,15 @@ | |
| if (optional | ||
| && (e.code() == CelException.Code.NO_SUCH_KEY || e.code() == CelException.Code.INDEX)) | ||
| yield OptionalValue.none(); | ||
| if (!optional | ||
| && (e.code() == CelException.Code.NO_SUCH_KEY | ||
| || e.code() == CelException.Code.INDEX)) { | ||
| // Container present but the key/index is missing: a deep unknown pattern intersecting | ||
| // this read path turns the hard error into an Unknown for resolve-and-retry; a | ||
| // resolution that supplies (or has supplied) an ancestor still raises the error. | ||
| Object intersect = ctx.attributeIntersect(path); | ||
| if (intersect != PartialState.NONE) yield intersect; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reference equality is intentional here: |
||
| } | ||
| throw e; | ||
| } | ||
| } | ||
|
|
@@ -749,18 +767,29 @@ | |
| private Object select(VirtualFrame frame, EvalContext ctx, boolean presence) { | ||
| Object operand = children[0].execute(frame, ctx); | ||
| Attribute parent = ctx.attribute(); | ||
| Object override = ctx.attributeRead(ctx.qualify(parent, name), presence); | ||
| Attribute path = ctx.qualify(parent, name); | ||
| Object override = ctx.attributeRead(path, presence); | ||
| if (presence) ctx.attribute(null); | ||
| if (override != PartialState.NONE) | ||
| return !presence | ||
| && !(override instanceof Unknown) | ||
| && (Boolean.TRUE.equals(value) || operand instanceof OptionalValue) | ||
| ? OptionalValue.of(override) | ||
| : override; | ||
| if (operand == PartialState.MISSING) throw missingAttribute(parent); | ||
| if (operand == PartialState.MISSING) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reference equality is intentional here: |
||
| // A deep unknown pattern (deeper than this hop) was invisible to `override` because | ||
| // AttributePattern.matches is one-directional; fall back to overlap semantics so that a | ||
| // missing receiver at this hop yields an Unknown instead of a hard UNDECLARED error, | ||
| // mirroring cel-go / cel-java. A resolution that has supplied an ancestor is left to | ||
| // surface the existing error. `attributeIntersect` only ever returns NONE or an Unknown, | ||
| // so the optional-lifting form used for `override` above is not needed here. | ||
| Object intersect = ctx.attributeIntersect(path); | ||
| if (intersect != PartialState.NONE) return intersect; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reference equality is intentional here: |
||
| throw missingAttribute(parent); | ||
| } | ||
| if (fieldRead != null && fieldRead.accepts(operand)) | ||
| return presence ? fieldRead.has(operand) : fieldRead.read(operand); | ||
| return selectValue(ctx, presence, operand); | ||
| return selectValue(ctx, presence, operand, path); | ||
| } | ||
|
|
||
| @com.oracle.truffle.api.CompilerDirectives.TruffleBoundary | ||
|
|
@@ -769,7 +798,7 @@ | |
| } | ||
|
|
||
| @com.oracle.truffle.api.CompilerDirectives.TruffleBoundary | ||
| private Object selectValue(EvalContext ctx, boolean presence, Object operand) { | ||
| private Object selectValue(EvalContext ctx, boolean presence, Object operand, Attribute path) { | ||
| if (operand instanceof Unknown) return operand; | ||
| if (extensionSelect) { | ||
| for (ObjectType type : ctx.environment.runtimeObjectTypes) | ||
|
|
@@ -790,13 +819,24 @@ | |
| boolean present = map.containsKey(name); | ||
| if (presence) return present; | ||
| if (lifted) return present ? OptionalValue.of(map.get(name)) : OptionalValue.none(); | ||
| if (!present) throw Values.error(CelException.Code.NO_SUCH_KEY, "no such key: " + name); | ||
| if (!present) { | ||
| // The container is present but the key is missing: a deep unknown pattern intersecting | ||
| // this read path means the missing key is part of the unknown attribute subtree, so | ||
| // surface an Unknown for resolve-and-retry instead of a hard NO_SUCH_KEY; a resolution | ||
| // that supplies (or has supplied) an ancestor steers the existing error path. | ||
| Object intersect = ctx.attributeIntersect(path); | ||
| if (intersect != PartialState.NONE) return intersect; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reference equality is intentional here: |
||
| throw Values.error(CelException.Code.NO_SUCH_KEY, "no such key: " + name); | ||
| } | ||
| return map.get(name); | ||
| } | ||
| for (ObjectType type : ctx.environment.runtimeObjectTypes) | ||
| if (type.accepts(operand)) { | ||
| if (!type.fields().containsKey(name)) | ||
| if (!type.fields().containsKey(name)) { | ||
| Object intersect = ctx.attributeIntersect(path); | ||
| if (intersect != PartialState.NONE) return intersect; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reference equality is intentional here: |
||
| throw Values.error(CelException.Code.NO_SUCH_FIELD, "no such field: " + name); | ||
| } | ||
| if (presence) return type.has(operand, name); | ||
| if (lifted) | ||
| return type.has(operand, name) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reference equality is intentional here:
PartialState.MISSING/NONEare identity-onlystatic final Objectsentinels, so.equals()would be a no-op at best and NPE-prone at worst (the receiver can be null, e.g. when an earlier read threw and was captured). This matches the existing convention throughoutExprNode(e.g.override != PartialState.NONEon the line above). Not changing.