Skip to content

Commit 7e14a0c

Browse files
committed
Add assertions for undefined variables
1 parent bfb548d commit 7e14a0c

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/engine/compiler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ std::shared_ptr<Block> Compiler::inputBlock(int id) const
289289
/*! Returns the index of the given variable. */
290290
unsigned int Compiler::variableIndex(std::shared_ptr<Entity> varEntity)
291291
{
292+
assert(varEntity);
292293
auto var = dynamic_cast<Variable *>(varEntity.get());
294+
assert(var);
293295
auto it = std::find(impl->variables.begin(), impl->variables.end(), var);
294296
if (it != impl->variables.end())
295297
return it - impl->variables.begin();

src/scratch/inputvalue.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ void InputValue::compile(Compiler *compiler)
3434
break;
3535

3636
case Type::Variable:
37+
assert(impl->valuePtr);
3738
compiler->addInstruction(vm::OP_READ_VAR, { compiler->variableIndex(impl->valuePtr) });
3839
break;
3940

4041
case Type::List:
42+
assert(impl->valuePtr);
4143
compiler->addInstruction(vm::OP_READ_LIST, { compiler->listIndex(impl->valuePtr) });
4244
break;
4345

0 commit comments

Comments
 (0)