google / google/emboss

Missing inner array type dimensions errors do not include correct source locations

Open
#153 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
92
Forks
30
PR merge metrics
No merged PRs in 30d

Description

We currently have a test that checks that "Array dimensions can only be omitted for the outermost dimension", [`ConstraintsTest.test_error_on_missing_inner_array_size`](https://github.com/google/emboss/blob/61e9a22768d268331141dec64cf1cd59572e81a8/compiler/front_end/constraints_test.py#L38):
```python
def test_error_on_missing_inner_array_size(self):
ir = _make_ir_from_emb("struct Foo:\n"
" 0 [+1] UInt:8[][1] one_byte\n")
error_array = ir.module[0].type[0].structure.field[0].type.array_type
self.assertEqual([[
error.error(
"m.emb",
error_array.base_type.array_type.element_count.source_location,
"Array dimensions can only be omitted for the outermost dimension.")
]], error.filter_errors(constraints.check_constraints(ir)))
```

This test passes as an error is generated and a source location is listed.

While working on a refactoring in #149 I noticed that the error itself is missing valid source locations: due to the nature of auto-generating fields as they're accessed `error_array.base_type.array_type.element_count.source_location` ends up yielding a default value which matches the default value generated by the compiler error.

We can reproduce this with the following:

```python
$ cat test.emb
struct Foo:
0 [+1] UInt:8[][1] one_byte
$ python3 ./embossc test.emb
test.emb:0:0: error: Array dimensions can only be omitted for the outermost dimension.
```

Note the error is at `0:0`.

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.