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

Allow using a complex type as an array element type #734

Merged
merged 1 commit into from
Jun 16, 2022

Conversation

Y-Nak
Copy link
Member

@Y-Nak Y-Nak commented Jun 4, 2022

close #730

  1. Allow using a complex type as an array element type
  2. Fix a bug that incorrect instruction is selected when the operands of a comp instruction are a signed type.

Example:

contract Foo {
    pub fn bar() -> i256 {
        let my_array: Array<Pair, 3> = [Pair::new(-1, 1), Pair::new(10, -10), Pair::new(-100, 100)]

        let sum: i256 = 0
        for pair in my_array {
            sum += pair.l1_norm()
        }

        return sum
    }
}

struct Pair {
    pub x: i256
    pub y: i256

    pub fn new(_ x: i256, _ y: i256) -> Pair {
        return Pair(x, y)
    }

    pub fn l1_norm(self) -> i256 {
        return abs(self.x) + abs(self.y)
    }
}

fn abs(_ val: i256) -> i256 {
    if val < 0 {
        return -val
    } else {
        return val
    }
}

NOTE:
Please start reviewing this after #729 is merged.

  • OPTIONAL: Update Spec if applicable

  • Add entry to the release notes (may forgo for trivial changes)

  • Clean up commit history

@Y-Nak Y-Nak mentioned this pull request Jun 6, 2022
7 tasks
Copy link
Collaborator

@sbillig sbillig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Sorry for the delay.

@sbillig sbillig merged commit 471714f into ethereum:master Jun 16, 2022
@Y-Nak Y-Nak deleted the complex-array-elem branch June 17, 2022 02:16
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

Successfully merging this pull request may close these issues.

Allow using complex type as array element type
2 participants