Skip to content

Creating variables makes statement get removed even with self #2231

@evantypanski

Description

@evantypanski

The following HILTI program has different behavior with optimizations and without:

module Foo {

import hilti;

type Test = struct() {
    method int<64> test();
    int<64> x;
};

method int<64> Test::test() {
    self.x = 5;
    return 1;
}

function void x() {
    local Test dat = [$x = 1];
    hilti::print(dat);
    local y = dat.test();
    hilti::print(dat);
}

x();
}
etyp:/Users/etyp/src/spicy jj:(r:zzw) $ hiltic -j test.hlt -g
[$x=1]
[$x=5]
etyp:/Users/etyp/src/spicy jj:(r:vtw) $ hiltic -j test.hlt
[$x=1]
[$x=1]

note that this is just because y is never marked as used so it gets rid of the statement. If you just do dat.test(); then it doesn't get removed.

I'm hitting this when finishing #2228, a test is failing because a method gets removed, and it gets removed despite using self (as a method call).

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Done

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions