Skip to content

Refactor codegen error reporting #1031

@volsa

Description

@volsa

Is your refactor request related to a problem? Please describe.
Currently we have some lines making use of map_err in our codegen code. While this is not an issue per-se, it can remove the initial diagnostic with a somewhat less detailed diagnostic (and thus error message). For example take the following code

TYPE STRUCT1 : STRUCT
    x : INT := 'wrong type';
END_STRUCT END_TYPE

Compiling it, will return "Some initial values were not generated", however initially a cannot_generate_string_literal diagnostic is returned, which is remapped to a cannot_generate_initializer diagnostic removing the previous diagnostic (and any other codegen error is later remapped to a cannot_generate_initializer error anyways because of the pipeline here).

Describe the solution you'd like
The given code should probably return the underlying root issue, namely a "Cannot generate String-Literal for type INT" error message (cannot_generate_string_literal). So either remapping diagnostics should maintain a reference

  • to any previous diagnostic (sort of like a stack-trace) or
  • only to the root issue.

Additional context
These remapping are only a problem because we map them to e.g. a SyntaxError which has no fields for references. One solution could be introducing an initial: Option<Diagnostic> field for all variants of the Diagnostics enum and on any remapping that field is "carried over".

cc @ghaith : IIRC you're already working on something similar to this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorinternal change, cleanup, code-style-improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions