google / google/xls

DSLX should resolve parametric impl's const

Open
#1,779 1 comment 0 reactions 1 assignee Claimed by @erinzmoore 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**
DSLX frontend does not seems to support using a const from a parametric impl.

**To Reproduce**

```
struct Foo {
}

impl Foo {
const N_PLUS_1 = N + u32:1;
}

fn foo() -> u32 {
Foo::N_PLUS_1
}

fn foo32() -> u32 {
foo()
}

#[test]
fn test_foo32() {
assert_eq(foo32(), u32:33);
}
```
throws the following error:
```
0009:
0010: fn foo() -> u32 {
0011: Foo::N_PLUS_1
~~~~~~~~~~~~~~^^ ParseError: Expected ':', got '::': Expect colon after type annotation in cast
0012: }
0013:
```

**Expected behavior**
I would expect the parser to resolve `Foo::N_PLUS_1` as `N + u32:1`.

Note that attempting to define a local type alias:
```
type F = Foo;
F::N_PLUS_1
```
produces a different error:
```
xls/dslx/constexpr_evaluator.cc:119
xls/dslx/type_system/deduce.cc:270
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce_colon_ref.cc:203
xls/dslx/type_system/deduce_colon_ref.cc:361
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:832
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:902
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/typecheck_invocation.cc:485
xls/dslx/type_system/deduce_invocation.cc:357
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:832
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:902
xls/dslx/type_system/deduce.cc:2145
xls/dslx/type_system/deduce.cc:2159
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce_ctx.cc:186
xls/dslx/type_system/typecheck_function.cc:198
xls/dslx/type_system/typecheck_module.cc:326
xls/dslx/type_system/typecheck_module.cc:326
xls/dslx/parse_and_typecheck.cc:102
xls/dslx/interpreter_main.cc:203
__main__.XlsRuntimeError('Error: INVALID_ARGUMENT: Expression @
```

Related: #1778

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.