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

Self-assignment does not work #71

Open
sunjay opened this issue May 14, 2017 · 0 comments
Open

Self-assignment does not work #71

sunjay opened this issue May 14, 2017 · 0 comments

Comments

@sunjay
Copy link
Owner

sunjay commented May 14, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant