Skip to content
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

value expression as variability condition #456

Merged
merged 2 commits into from
Dec 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading