Fix bogus translation of nested conditionals with elseif clauses
commit476404b134970e7cfe39dbfd5edad0877f985fb3
authorKris Katterjohn <katterjohn@gmail.com>
Tue, 22 Dec 2020 22:45:17 +0000 (22 17:45 -0500)
committerKris Katterjohn <katterjohn@gmail.com>
Tue, 22 Dec 2020 22:45:17 +0000 (22 17:45 -0500)
treecda78029f025df267f674a73a417aa88a651a347
parent1de414deb1e661e69bad0fa71b611e073395aee3
Fix bogus translation of nested conditionals with elseif clauses

This is an old bug that was present before Maxima 5.0.  It doesn't
appear that this bug was present in Macsyma because I haven't found
any evidence that elseif existed in Macsyma.

The translation of a conditional with another conditional directly
nested in an elseif clause has been totally wrong.  Using else-if
(else if) instead of elseif would work fine.

An example of some particularly bad behavior:

  if false then
    'wtf1
  elseif false then
    if true then
      'wtf2
    else
      'wtf3
  else
    correct

was being incorrectly translated like

  if false then
    'wtf1
  else if true then
    'wtf2
  else
    'wtf3

So this would yield wtf2 instead of correct.

Some portions of code were not updated to correctly handle elseif
when it was first introduced.  See commits d89c9965 and 4cc510ca for
some late fixes related to elseif.

The problem in the translator has been due to an optimization for
the else-if case.  The check for when to apply the optimization was
not particularly careful and the introduction of elseif caused the
translator to incorrectly apply the optimization technique to elseif
clauses like the one above.

The optimization is still useful for the else-if case, so we're
keeping it.  We're just more careful about when to apply it now.

No problems with the test suite or share test suite.
tests/rtest_translator.mac runs as expected, with new tests.
src/transl.lisp
tests/rtest_translator.mac