Skip to content

Coditional method invocation may have an incorrect side effect #333

@ggleyzer

Description

@ggleyzer

The code to reproduce the bug:

module Reproducer {
    void run() {
        Char[] chars = new Array<Char>(2);
        Int offset = 0;
        if (chars[offset++] := next()) {
            assert offset == 1;
        } else {
            // the offset must not have been incremented, but it has been
            assert offset == 0;
        }
    }

    conditional Char next() = False;
}

Currently, the offset++ increment happens before the conditional method next() is called, which is wrong. It should only happen after next{} returns with a positive (True) result.

Similarly, the following code works incorrectly; the index() method must not be called upon a negative response from next() method.

module Reproducer2 {
    void run() {
        Char[] chars = new Array<Char>(2);
        chars[index()] := next();
    }

    conditional Char next() = False;

    Int index() {
        assert False as "This should not be called";
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions