Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A dynamic array declared in a function cannot be substituted away. #2458

Closed
pirapira opened this issue Jun 23, 2017 · 5 comments
Closed

A dynamic array declared in a function cannot be substituted away. #2458

pirapira opened this issue Jun 23, 2017 · 5 comments
Labels
closed due inactivity The issue/PR was automatically closed due to inactivity. language design :rage4: Any changes to the language, e.g. new features stale The issue/PR was marked as stale because it has been open for too long.

Comments

@pirapira
Copy link
Member

pirapira commented Jun 23, 2017

The violated property

In general,

<type> v = a;
<code contaning v>

should be equivalent to

<code containing a>

if a does not have side-effects.

The violation

However, this property does not hold in Solidity because

contract C {
    uint[] a;
    uint[] b;
    function f() {
        uint[] ref = a;
        ref = b;
    }
}

behaves quite differently from

contract C {
    uint[] a;
    uint[] b;
    function f() {
        a = b;
    }
}

The latter performs elementwise copy while the former does not.

@chriseth
Copy link
Contributor

Solidity is not the only language that does not have this property. Python for example, a language that is usually considered to be very intuitive or at least easy to learn behaves like that:

>>> a = [1,2,3]
>>> b = [4,5]
>>> ref = a
>>> ref = b
>>> a
[1, 2, 3]
>>> b
[4, 5]
>>> a = [1,2,3]
>>> b = [4,5]
>>> a = b
>>> a
[4, 5]
>>> b
[4, 5]

@chriseth
Copy link
Contributor

In general, I think that #2435 should make this distinction clear to the programmer.

@pirapira
Copy link
Member Author

Yes, I have the same complaint against Python.

@pirapira
Copy link
Member Author

After #2435, it should be straightforward to fix this issue, whether element-wise copying into a reference is allowed or not.

@axic axic added the language design :rage4: Any changes to the language, e.g. new features label Jul 28, 2018
@NunoFilipeSantos NunoFilipeSantos added the stale The issue/PR was marked as stale because it has been open for too long. label Nov 25, 2022
@github-actions
Copy link

Hi everyone! This issue has been closed due to inactivity.
If you think this issue is still relevant in the latest Solidity version and you have something to contribute, feel free to reopen.
However, unless the issue is a concrete proposal that can be implemented, we recommend starting a language discussion on the forum instead.

@github-actions github-actions bot added the closed due inactivity The issue/PR was automatically closed due to inactivity. label Jan 27, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed due inactivity The issue/PR was automatically closed due to inactivity. language design :rage4: Any changes to the language, e.g. new features stale The issue/PR was marked as stale because it has been open for too long.
Projects
None yet
Development

No branches or pull requests

4 participants