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

[Bug]: Temp variable for new dynamic array has wrong type #2016

Open
kevinclancy opened this issue Jul 1, 2023 · 2 comments
Open

[Bug]: Temp variable for new dynamic array has wrong type #2016

kevinclancy opened this issue Jul 1, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@kevinclancy
Copy link
Contributor

kevinclancy commented Jul 1, 2023

Describe the issue:

When we print slithir for the following source file:

contract Test {
    function test() external {
        int[] memory a = new int[](5);
    }
}

the temp variable in the generated IR has the wrong type. It's an array of arrays instead of a 1-dimensional array:

INFO:Printers:Contract Test
        Function Test.test() (*)
                Expression: a = new int256[](5)
                IRs:
                        TMP_1int256[][])  = new int256[](5)
                        a(int256[]) := TMP_1(int256[][])

Code example to reproduce the issue:

contract Test {
    function test() external {
        int[] memory a = new int[](5);
    }
}

Version:

0.9.5

Relevant log output:

INFO:Printers:Contract Test
        Function Test.test() (*)
                Expression: a = new int256[](5)
                IRs:
                        TMP_1int256[][])  = new int256[](5)
                        a(int256[]) := TMP_1(int256[][])
@kevinclancy kevinclancy added the bug-candidate Bugs reports that are not yet confirmed label Jul 1, 2023
@0xalpharush 0xalpharush added bug Something isn't working and removed bug-candidate Bugs reports that are not yet confirmed labels Jul 1, 2023
@0xalpharush 0xalpharush changed the title [Bug-Candidate]: Temp variable for new dynamic array has wrong type [Bug]: Temp variable for new dynamic array has wrong type Jul 1, 2023
@0xalpharush
Copy link
Contributor

The linked PR doesn't handle late type conversion for literals in the case of an EventCall, NewStructure, or NewContract.

contract New {
    constructor(int x) {
    }
    function b(int a) external {

    }
}
contract Test {
    struct X {
        int x;
    }
    event Log(int message);
    function test() external {
        emit Log(5);
        New n = new New(5);
        n.b(5);
        X(5);
        
    }
}

@0xalpharush
Copy link
Contributor

similar to make the contract available in NewContract we need to that for EventCall and make Event readily available #2370

# TODO: implement instances lookup for events, NewContract

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants