Unparsing of symbolic with minus set using python fails
Summary
Unparsing of a model where a value has been set using the python api to minus some reference fails.
Steps to reproduce
kat1 = finesse.Model("""
m m1 phi=22
m m2 phi=-m1.phi
""")
print(kat1.unparse())
works, while the equivalent
kat = finesse.Model()
kat.parse("""
m m1 phi=22
m m2
""")
kat.m2.phi=-kat.m1.phi.ref
print(kat.unparse())
fails with an assert since the - is interpreted as a binary '-' operator instead of the unary '-' operator.
Bug behavior
The above code fails on the assertion in src/finesse/script/generator.py line 805 with an AssertionError and a long stack trace. The reason is that the condition in line 800 evaluates as true. In the first example above, the '-' is already parsed and internally presented as neg() and hence not in self.spec.binary_operators.
What is the expected correct behavior?
I would expect both pieces of code to be the exact same.
Relevant logs and/or screenshots
(Paste any relevant logs - please use code blocks (```) to format console output, logs, and code, as it's very hard to read otherwise.)
Possible Fixes
I think that:
- the test in line 800 should include a test on the num of arguments
- there should be a second test for unary operators, checking not for 'pos' and 'neg' but for '+' and '-'.
It's not entirely clear why we sometimes get 'neg' sometimes '-'. Maybe the setter of e.g. phi doesn't work properly.
Labels
Area of the bug
- Parser (of the KatScript) Use Parser::legacy if you are parsing legacy files </label Parser>