Skip to content
This repository was archived by the owner on Feb 3, 2020. It is now read-only.
This repository was archived by the owner on Feb 3, 2020. It is now read-only.

Self-assignment does not work #71

@sunjay

Description

@sunjay

Consider the following code:

let x: bool = true;
stdout.println(x);
x = !x;
stdout.println(x);

You would expect it to output:

1
0

However, in reality it outputs:

1
1

This is a bug in the assignment implementation. The current implementation unconditionally zeros the target (lhs) of the assignment. This fails when doing self-assignment.

To fix this is non-trivial because the assignment does not know about its target at all. It treats the rhs expression as a black box and there is no way to inspect the result.

The more fundamental issue with this code is that it assumes that it is decidable whether the target should be zeroed before expression::into_operations is called. The assumption that expression::into_operation makes about the target being zero is just not sound. We should probably add a parameter into that function to indicate whether the target was just initialized or may need to be zeroed. Then expression::into_operations can decide what the proper course of action is.


Another related problem: This works for some reason:

let a: bool = a;

Notice that a can be used before it is properly initialized.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions