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 error messages in shadowing errors #5502

Closed
ironcev opened this issue Jan 22, 2024 · 0 comments · Fixed by #5532
Closed

Missing error messages in shadowing errors #5502

ironcev opened this issue Jan 22, 2024 · 0 comments · Fixed by #5532
Assignees
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged

Comments

@ironcev
Copy link
Member

ironcev commented Jan 22, 2024

All the shadowing errors (for consts, symbols, and generic parameters) are missing errors on the compiler output in the case of the same identifier. The reason is using Idents in the errors and extracting spans from them. This is exactly what we should do, but since the span is not a part of the Ident's hash, two different error messages (different spans) with the sameIdent e.g. a variable or a constant, will end up having the same hash and will be removed by the deduplication of the error messages which differentiate the messages based on their hash.

The solution is to use IdentUnique instead of Ident.

To reproduce, create a script with lib.sw like this:

library;

pub struct Struct { }

and the main.sw:

script;

mod lib;

use lib::Struct;
use lib::Struct;
use lib::Struct;

const X = 0;

fn main() -> () {
    let X = 1;
    let X = 2;

    let y = 3;

    {
        const y = 4;
    }

    {
        const y = 6;
    }
}

fn generic<T, T, T>(_x: T) { }

When compiling the script, the shadowing messages will appear only for the first error. The second one will be falsely removed by the deduplication.

Related to #4818.

@ironcev ironcev added bug Something isn't working compiler General compiler. Should eventually become more specific as the issue is triaged compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Jan 22, 2024
@ironcev ironcev self-assigned this Jan 22, 2024
ironcev added a commit that referenced this issue Jan 31, 2024
## Description

Fixes #5502.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [ ] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler General compiler. Should eventually become more specific as the issue is triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant