Skip to content

Commit

Permalink
value expression as variability condition (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner authored Dec 25, 2024
1 parent 9a6d7d6 commit 554f9e7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/resolver/solver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,21 @@ export default class Solver {
* Assume that expression is a value expression that returns a boolean
* Thus, {@param expression} can be in reality also of type {@link ValueExpression}
*/
const result = this.evaluateValueExpression(expression, context)
const result = this.evaluateValueExpressionAsLogic(expression, context)
assert.isBoolean(result)
return this.transformLogicExpression(result, context)
}

evaluateValueExpressionAsLogic(expression: ValueExpression, context: ExpressionContext): boolean {
const result = this.evaluateValueExpression(expression, context)

if (check.isBoolean(result)) return result
if (check.isString(result)) return true
if (check.isNumber(result)) return result > 0

throw new Error(`Unexpected value expression treated as logic "${utils.pretty(expression)}"`)
}

evaluateValueExpression(expression: ValueExpression, context: ExpressionContext): InputAssignmentValue {
if (check.isObject(expression) && !check.isArray(expression)) {
if (check.isDefined(expression._cached_result)) return expression._cached_result
Expand Down

0 comments on commit 554f9e7

Please sign in to comment.