Fix compilation of nested boolean operations#1225
Conversation
| self.emit(Instruction::Pop); | ||
| } | ||
| if let Some(false_label) = false_label { | ||
| self.emit(Instruction::Duplicate); |
There was a problem hiding this comment.
Please add the test case as you mentioned in the pull request comment.
There was a problem hiding this comment.
This compile_test is fairly complex. It implements short circuit evaluation.
Please check carefully the logic of this function. I believe the EvalContext::Expression is for the case where an expression on the stack is desired.
It is probably a good idea to expand on our snippets here, so that we cover all cases.
| @@ -1303,11 +1303,9 @@ impl<O: OutputStream> Compiler<O> { | |||
| self.emit(Instruction::Pop); | |||
There was a problem hiding this comment.
I would expect the same change to be required for this line. Still I do not fully grasp the problem.
|
Suggested test snippet: run = 1
timeTaken = 33
r = (22, run, run != 1 and "s" or "", timeTaken)
assert r == (22, 1, '', 33)On rustpython, this now gives: |
|
Alright, it's taken me a while to fully grasp the issue, but I think I've got it.
|
|
Do you have any ideas for how to tackle this @windelbouwman? Maybe a flag in |
|
No, I don't think an extra flag is a good option. Basically, the switch on I do not have a good solution for this, except that I would try to first think of all the different test cases, and really write them out. Only then we might get the logic right, if we cover all combinations. I think it's about 8 different combinations, so we should do this first. |
|
Btw, the longer I look at this For example: If you set both |
|
I can have a look at it if you like? I looked at the CPython sourcecode, I think we can get ideas from there. I'll check micropython as well how they did it. |
|
Sorry about leaving this mess. I got stuck on these bugs and decided to take a break and come back to it (which never happened). |
|
@cthulahoops no problem! All will be fine :). |
|
Okay, I got a pretty good idea about how to solve this. Will open another pull request. |
|
I'll close this, then. :) |
|
@coolreader18 did you intend to merge this? Or close this pull request? |
|
Whoops, I meant to close it. I'll undo it. |
I ran into this in
unittest/runner.py, which has this code:It was duplicating the False from the
!=expression but not popping it off the stack, so when BuildTuple was called it included that original False as the first element of the tuple.