google / google/xls

impl should recognize the concrete struct type as Self

Open
#2,017 1 comment 0 reactions 1 assignee Claimed by @richmckeever View on GitHub
bug dslx 🧦 sox
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

**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 {
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.