Skip to content

impl should recognize the concrete struct type as Self #2017

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

Open
proppy opened this issue Mar 27, 2025 · 1 comment
Open

impl should recognize the concrete struct type as Self #2017

proppy opened this issue Mar 27, 2025 · 1 comment
Assignees
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end 🧦 sox

Comments

@proppy
Copy link
Member

proppy commented Mar 27, 2025

Describe the bug
Currently it seems that impl method only accept Self as the receiver type, should we support the concrete struct type as well?

To Reproduce

struct Params {
  a: u32,
}

impl Params {
  fn new(a: u32) -> Params {
    Params {
      a
    }
  }
  fn b(self: Params) -> u32 {
    self.a / u32:2
  }
}

fn params() -> Params {
  Params::new(u32:42)
}

#[test]
fn params_test() {
  let p = params();
  assert_eq(p.b(), u32:21);
}

produces the following error:

0023: fn params_test() {
0024:   let p = params();
0025:   assert_eq(p.b(), u32:21);
~~~~~~~~~~~~~~~~~~~~~^^ ArgCountMismatchError: Expected 1 parameter(s) but got 0 arguments.
0026: }

Expected behavior

  fn b(self: Params) -> u32 {

get aliased to:

  fn b(self: Self) -> u32 {
@proppy proppy added bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end 🧦 sox labels Mar 27, 2025
@richmckeever
Copy link
Collaborator

Let's check if this works in v2.

@richmckeever richmckeever self-assigned this Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working or is incorrect dslx DSLX (domain specific language) implementation / front-end 🧦 sox
Projects
Status: No status
Development

No branches or pull requests

2 participants