miker2 / flexi_config_reader

A flexible configuration format that supports templated tables and referencing of existing keys.
MIT License
3 stars 1 forks source link

Math code crashes without a useful error message when variable isn't resolved #70

Closed miker2 closed 1 year ago

miker2 commented 1 year ago

Example:

proto my_proto {
  parent = $PARENT
  var = "${PARENT}.$VAR"  # An example of using variables in a string
  center = {{ 0.5 * ($MAX - ${MIN}) }}
}

reference my_proto as concrete {
  $PARENT = $PARENT_NAME
  $VAR = "fuzz"
}

Because $MIN and $MAX aren't defined, this leads to a segfault. Instead, a useful exception should probably be thrown to make debugging easier.

miker2 commented 1 year ago

The code fails when trying to evaluate the mathematical expression in stack::evalBack() due to the assert(vs_.size() == ops_.size() + 1)

I think the right solution is to check within replaceProtoVar that an expression (or any type) has no more variables once all proto vars have been resolved.