Skip to content

impl should recognize the concrete struct type as Self #2017

Open
@proppy

Description

@proppy

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 {

Metadata

Metadata

Assignees

Labels

bugSomething isn't working or is incorrectdslxDSLX (domain specific language) implementation / front-end🧦 sox

Type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions