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

Support SomeStruct::new() function call syntax #599

Closed
sbillig opened this issue Nov 29, 2021 · 1 comment
Closed

Support SomeStruct::new() function call syntax #599

sbillig opened this issue Nov 29, 2021 · 1 comment

Comments

@sbillig
Copy link
Collaborator

sbillig commented Nov 29, 2021

What is wrong?

Type-associated functions can currently be called by using a . but not a ::. For example:

struct Rectangle:
  h: u256
  w: u256
  pub fn square(x: u256) -> Rectangle:
    return Rectangle(h=x, w=x)
  pub fn area(self) -> u256:
    return self.h * self.w

fn do_square_things():
  let s: Rectangle = Rectangle::square(10)
  assert s.area() == 100

The Rectangle::square(10) call above panics with something like

thread 'struct_fn' panicked at 'not yet implemented: cannot access items in types yet', crates/analyzer/src/namespace/items.rs:106:30

changing it to Rectangle.square(10) works. This syntax should be disabled, and :: should be fixed.

How can it be fixed

🧑‍💻

@sbillig
Copy link
Collaborator Author

sbillig commented Nov 29, 2021

Whoops, duplicate of #241

@sbillig sbillig closed this as completed Nov 29, 2021
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

1 participant