Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
EricRahm opened this issue Jul 8, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@EricRahm
Copy link
Collaborator

EricRahm commented Jul 8, 2024

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:

  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:

$ 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.

@EricRahm
Copy link
Collaborator Author

EricRahm commented Jul 8, 2024

FYI @robrussell

EricRahm added a commit to EricRahm/emboss that referenced this issue Jul 8, 2024
This adds a note on an existing latent issue in the source location
provided in errors related to missing inner array sizes. Issue google#153 has
been filed to track the bug.
@reventlov
Copy link
Collaborator

This does point to a larger hole in the unit tests for error messages: they should either check the actual numbers for the source locations (thorough, but slightly brittle) or at least check that the source locations are not defaulted.

due to the nature of auto-adding fields as they're accessed

Just a minor point: (in the current implementation) fields aren't added as they are accessed, but they do have default values if they are read without being accessed. ...element_count.HasField('source_location') should still return False here.

@EricRahm
Copy link
Collaborator Author

EricRahm commented Jul 9, 2024

Just a minor point: (in the current implementation) fields aren't added as they are accessed, but they do have default values if they are read without being accessed. ...element_count.HasField('source_location') should still return False here.

Reworded to "auto-generating"

@jasongraffius jasongraffius added the bug Something isn't working label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants