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

Enforce key value syntax to initialize structs #234

Closed
cburgdorf opened this issue Feb 5, 2021 · 2 comments
Closed

Enforce key value syntax to initialize structs #234

cburgdorf opened this issue Feb 5, 2021 · 2 comments

Comments

@cburgdorf
Copy link
Collaborator

What is wrong?

When #203 lands, we'll have basic support for structs.

struct House:
    price: u256
    size: u256
    vacant: bool

contract City:

    pub def get_price() -> u256:
        building: House = House(300, 500, true)

        assert building.size == 500
        assert building.price == 300
        assert building.vacant

        return building.price

The current syntax for initializing structs is the same as for all function invocations (e.g. House(300, 500, true)) in the example above.

I believe for better clarity struct initialization should look like one of these:

A. House(size=500, price=300, vacant=true)

or B. House(size:500, price:300, vacant:true)

How can it be fixed

  1. Settle on syntax

  2. Make modifications to the parser

@cburgdorf
Copy link
Collaborator Author

@g-r-a-n-t What is your opinion here? I think we should go with House(size=500, price=300, vacant=true) and forbid the current syntax (House(500, 300, true))

@g-r-a-n-t
Copy link
Member

I vote A.

cburgdorf added a commit to cburgdorf/fe that referenced this issue Feb 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants