Bad error when underspecified parametric binding mixes with type mismatch
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
**Describe the bug**
When you have both 1) a missing parametric binding in a parametric function invocation and 2) a mismatch between return type annotation and function body return type, you get the following error:
E1107 09:53:17.601245 3402 command_line_utils.cc:50] Could not extract a textual position from error message: INVALID_ARGUMENT: Expected concrete type dimension to be integral; got: N
=== Source Location Trace: ===
xls/dslx/type_system/type.cc:337
xls/dslx/type_system/type_zero_value.cc:212
xls/dslx/type_system/type_zero_value.cc:248
xls/dslx/type_system/deduce_invocation.cc:451
...
**To Reproduce**
```
type Foo = bits[8];
fn foo() -> Foo { zero!() }
fn main() { let foo = foo(); }
```
**Expected behavior**
Alert user of one or both type errors, as in the following cases:
If you change the `foo` return type annotation to `Foo[N]`, then you get the following reasonable error:
```
0014: fn main() { let foo = foo(); }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ TypeInferenceError: uN[8][N] Instantiated return type did not have the following parametrics resolved: N
```
If you instead add the parametric binding in `main`, i.e. `fn main() { let foo = foo(); }`, you get:
```
0012: fn foo() -> Foo { zero!() }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^-----------------^ XlsTypeError: Return type of function body for 'foo' did not match the annotated return type.
Type mismatch:
uN[8]
vs uN[8][8]
```
**Additional context**
Stack trace for the error shown below:
E1107 09:53:17.601245 3402 command_line_utils.cc:50] Could not extract a textual position from error message: INVALID_ARGUMENT: Expected concrete type dimension to be integral; got: N
=== Source Location Trace: ===
xls/dslx/type_system/type.cc:337
xls/dslx/type_system/type_zero_value.cc:212
xls/dslx/type_system/type_zero_value.cc:248
xls/dslx/type_system/deduce_invocation.cc:451
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:808
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:878
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/typecheck_invocation.cc:485
xls/dslx/type_system/deduce_invocation.cc:310
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce_ctx.cc:186
xls/dslx/type_system/deduce.cc:379
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:808
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:878
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
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:98
: INVALID_ARGUMENT: Provided status is not in recognized error form: INVALID_ARGUMENT: Expected concrete type dimension to be integral; got: N
=== Source Location Trace: ===
xls/dslx/frontend/bindings.cc:55
Error: INVALID_ARGUMENT: Expected concrete type dimension to be integral; got: N
=== Source Location Trace: ===
xls/dslx/type_system/type.cc:337
xls/dslx/type_system/type_zero_value.cc:212
xls/dslx/type_system/type_zero_value.cc:248
xls/dslx/type_system/deduce_invocation.cc:451
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:808
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:878
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/typecheck_invocation.cc:485
xls/dslx/type_system/deduce_invocation.cc:310
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce_ctx.cc:186
xls/dslx/type_system/deduce.cc:379
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:808
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
xls/dslx/type_system/deduce_ctx.cc:131
xls/dslx/type_system/deduce.cc:878
xls/dslx/type_system/deduce.cc:2081
xls/dslx/type_system/deduce.cc:2095
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:98
xls/dslx/interpreter_main.cc:199
Error parsing and type checking DSLX source file: foo.x
Contributor guide
Assessment
This issue has not been assessed yet.