Skip to content

Propagate errors in expr evaluation#489

Merged
ducky64 merged 4 commits into
masterfrom
error-prop
May 19, 2026
Merged

Propagate errors in expr evaluation#489
ducky64 merged 4 commits into
masterfrom
error-prop

Conversation

@ducky64
Copy link
Copy Markdown
Collaborator

@ducky64 ducky64 commented May 19, 2026

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ErrorValue propagation to several ExprEvaluate evaluation routines (binary, binarySet, unary, unarySet, range, extract, and if-then-else condition).
  • 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
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

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
}
@ducky64 ducky64 merged commit 9cfff0c into master May 19, 2026
12 checks passed
@ducky64 ducky64 deleted the error-prop branch May 19, 2026 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants