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

Internal compiler error on storage pointer casts and assignments. #4948

Closed
ekpyron opened this issue Sep 11, 2018 · 7 comments
Closed

Internal compiler error on storage pointer casts and assignments. #4948

ekpyron opened this issue Sep 11, 2018 · 7 comments

Comments

@ekpyron
Copy link
Member

ekpyron commented Sep 11, 2018

The following crashes with "InternalCompilerError: Invalid conversion to storage type." for 0.4.24 and develop.

contract C {
        uint[] a;
        uint[] b;
        function f() public view {
            uint[] storage c = a;
            uint[] storage d = b;
            d = uint[](c);
        }
}

The same for base types other than uint.

Found during #4911.

@ekpyron
Copy link
Member Author

ekpyron commented Sep 11, 2018

Related, but not entirely a duplicate: #4901.

@ekpyron
Copy link
Member Author

ekpyron commented Sep 11, 2018

Same for:

 contract C {
        uint[] a;
        uint[] b;
        function f() public view {
            uint[] storage c = a;
            uint[] memory d = b;
            d = uint[](c);
        }
}

@liangdzou
Copy link
Contributor

#4901 is fixed in PR 4904. I do not know why Chriseth stoped respond on the PR for more than 5 days.

@liangdzou
Copy link
Contributor

This issue looks interesting. The conversion looks valid since the base type is exactly the same.

@liangdzou
Copy link
Contributor

The type analysis for type conversion actually will always convert array pointer to array ref since array inherits from ReferenceType. Therefore, the target type will be a reference, instead of a pointer which makes the assertion to be violated.
@chriseth suggested me to add a branch to only allow bytes and string array conversion. I have added tests in the PR4904, this issue is fixed by adding the restriction. All code and the test are added to the PR.

@chriseth
Copy link
Contributor

Something here is very wrong. In T(x) for a type T, the check whether conversion is possible should check whether a conversion to a pointer can be done. After the conversion has happened, the result should again be a reference, I think. But perhaps we should rather fully re-architect this and add the copyof operator.

@liangdzou
Copy link
Contributor

@chriseth Actually, the array pointer is modified to reference before checking if it is possible to convert.

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

No branches or pull requests

3 participants