Skip to content

[Bug]: IR disorder in nested ternary operation #1797

Open
@Troublor

Description

@Troublor

Describe the issue:

When one ternary expression is used nestedly as a condition of another ternary operation, the condition IR operation of the outer ternary expression is missing.

In the following bug-revealing example, the two cases of inner ternary expression x != 10 ? x > 10 : x < 10 is assigned to TMP_1 and TMP_2, respectively.
However, the outer ternary, (x != 10 ? x > 10 : x < 10) ? 1 : 2 is not converted to IR operations.
There should be some Condition operation for the outer ternary expression.
For example, CONDITION ϕ[TMP_1, TMP_2] guarding the two return cases.

Code example to reproduce the issue:

contract A {
    function foo(uint x) public returns (uint) {
        return (x != 10 ? x > 10 : x < 10) ? 1 : 2;
    }
}

Version:

0.9.3

Relevant log output:

INFO:Printers:Contract A
        Function A.foo(uint256) (*)
                Expression: 1
                IRs:
                        RETURN 1
                Expression: 2
                IRs:
                        RETURN 2
                Expression: x != 10
                IRs:
                        TMP_0(bool) = x != 10
                        CONDITION TMP_0
                Expression: (x > 10)
                IRs:
                        TMP_1(bool) = x > 10
                Expression: (x < 10)
                IRs:
                        TMP_2(bool) = x < 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcfgir

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions