Skip to content

Enable proper bytesX typing for the result of .split() and .slice() #178

@mr-zwets

Description

@mr-zwets

We should fix the length of bytes types when using split:

bytes2 firstTwoBytes = test.split(2)[0];

The above does not work, when it should always be possible to type the length of the first element of the tuple. It should only be possible to type the length of the second element when the length of the original bytes element is typed.

The typing when getting both elements of the tuple is also wrong:

contract Demo() {
    function example(bytes4 test) {
        bytes3 firstHalf , bytes8 secondHalf = test.split(2);
        require(firstHalf .length == 2);
        require(secondHalf.length == 2);
    }
}

firstHalf can only be bytes2 here, and secondHalf can also only be bytes2, because the original length of the bytes element is typed

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    cashc-compilerRelates to the cashc compiler

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions