Skip to content

Commit 250713a

Browse files
committed
Check assumptions during simulation
1 parent eb2c802 commit 250713a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

quint/src/runtime/impl/compilerImpl.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,30 @@ export class CompilerVisitor implements IRVisitor {
158158
return this.errorTracker.runtimeErrors
159159
}
160160

161+
exitAssume(assume: ir.QuintAssume) {
162+
const comp = this.compStack.pop()
163+
if (comp === undefined) {
164+
this.errorTracker.addCompileError(assume.id, 'QNT501', `No expression for ${assume.name} on compStack`)
165+
return
166+
}
167+
168+
const result = comp.eval()
169+
if (result.isLeft()) {
170+
this.errorTracker.addRuntimeError(assume.id, result.value)
171+
return
172+
}
173+
174+
const value = result.value.toQuintEx(zerog)
175+
if (value.kind !== "bool") {
176+
this.errorTracker.addRuntimeError(assume.id, { code: 'QNT509', message: 'Assume must be a boolean expression' })
177+
return
178+
}
179+
180+
if (!value.value) {
181+
this.errorTracker.addRuntimeError(assume.id, { code: 'QNT510', message: 'Assumption failed' })
182+
}
183+
}
184+
161185
exitOpDef(opdef: ir.QuintOpDef) {
162186
// Either a runtime value, or a def, action, etc.
163187
// All of them are compiled to callables, which may have zero parameters.

0 commit comments

Comments
 (0)