Propagate errors in expr evaluation#489
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the compiler’s expression evaluation to prioritize propagating ErrorValue results through enclosing expressions, preventing crashes caused by type-mismatch exceptions when an inner expression has already errored.
Changes:
- Added early
ErrorValuepropagation to severalExprEvaluateevaluation routines (binary,binarySet,unary,unarySet,range,extract, andif-then-elsecondition). - Updated/expanded const-prop tests to cover error propagation through outer expressions, and clarified an existing test name.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| compiler/src/main/scala/edg/compiler/ExprEvaluate.scala | Propagates ErrorValue operands early to avoid throwing on outer expression evaluation. |
| compiler/src/test/scala/edg/compiler/ConstPropAssignTest.scala | Renames an existing test for clarity and adds a new test asserting ErrorValue propagation behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| (lhs, rhs) match { // errors propagation takes priority | ||
| case (ErrorValue(lhsMsg), ErrorValue(rhsMsg)) => | ||
| return ErrorValue(Some(Seq(lhsMsg, rhsMsg).flatten.mkString("; "))) |
|
|
||
| (lhs, rhs) match { // errors propagation takes priority | ||
| case (ErrorValue(lhsMsg), ErrorValue(rhsMsg)) => | ||
| return ErrorValue(Some(Seq(lhsMsg, rhsMsg).flatten.mkString("; "))) |
Comment on lines
335
to
344
| (vals, emptyValue) match { // errors propagation takes priority | ||
| case (ErrorValue(valsMsg), ErrorValue(emptyValueMsg)) => | ||
| return ErrorValue(Some(Seq(valsMsg, emptyValueMsg).flatten.mkString("; "))) | ||
| case (ErrorValue(_), _) => return vals | ||
| case (_, ErrorValue(_)) => return emptyValue | ||
| case _ => () // continue with normal evaluation | ||
| } | ||
|
|
||
| (unarySet.op, vals) match { | ||
| case (_, ArrayValue.Empty(_)) => emptyValue |
|
|
||
| (vals, emptyValue) match { // errors propagation takes priority | ||
| case (ErrorValue(valsMsg), ErrorValue(emptyValueMsg)) => | ||
| return ErrorValue(Some(Seq(valsMsg, emptyValueMsg).flatten.mkString("; "))) |
Comment on lines
+438
to
+442
| def evalRange(range: expr.RangeExpr, minimum: ExprValue, maximum: ExprValue): ExprValue = (minimum, maximum) match { | ||
| case (ErrorValue(minimumMsg), ErrorValue(maximumMsg)) => | ||
| ErrorValue(Some(Seq(minimumMsg, maximumMsg).flatten.mkString("; "))) | ||
| case (ErrorValue(_), _) => minimum | ||
| case (_, ErrorValue(_)) => maximum |
Comment on lines
+460
to
+464
| (container, index) match { | ||
| case (ErrorValue(containerMsg), ErrorValue(indexMsg)) => | ||
| ErrorValue(Some(Seq(containerMsg, indexMsg).flatten.mkString("; "))) | ||
| case (ErrorValue(_), _) => container | ||
| case (_, ErrorValue(_)) => index |
Comment on lines
+329
to
+333
| // note this does not short circuit out emptyValue if vals is not empty | ||
| ErrorValue.aggregate(Seq(vals, emptyValue)) match { | ||
| case Some(errorValue) => return errorValue // errors propagation takes priority | ||
| case None => () // continue with normal evaluation | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously it stopped error values at param boundaries, but it would still crash on an outer expr from type mismatch.
This adds a priority error propagation to prevent compiler crashes.