Skip to content

Improve error message for name shadowing #8532

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

Closed
pfgithub opened this issue Apr 14, 2021 · 0 comments
Closed

Improve error message for name shadowing #8532

pfgithub opened this issue Apr 14, 2021 · 0 comments
Labels
accepted This proposal is planned. frontend Tokenization, parsing, AstGen, Sema, and Liveness. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@pfgithub
Copy link
Contributor

Currently, the same error message is used for declaring a variable twice in the same scope and shadowing a variable from a parent scope

const X = 0;
const X = 0; // redefinition of 'X'

const Y = 0;
{
    const Y = 0; // redefinition of 'Y'
}

const Z = 0;
const Demo = struct {
    const Z = 0; // redefinition of 'Z'
};

This leads to confusion such as #8522 because the error, especially in structs, makes it sound like the declaration in the inner namespace has somehow ended up in the top level namespace instead of where it actually is.

This could be changed to something like name '…' shadows name from outer scope or something similar to make it clear that the declaration is in the right place and the issue is with name shadowing.

const X = 0;
const X = 0; // redefinition of 'X'

const Y = 0;
{
    const Y = 0; // name 'Y' shadows name from outer scope
}

const Z = 0;
const Demo = struct {
    const Z = 0; // name 'Z' shadows name from outer scope
};
@andrewrk andrewrk added accepted This proposal is planned. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. labels Apr 15, 2021
@andrewrk andrewrk added this to the 0.9.0 milestone Apr 15, 2021
@andrewrk andrewrk added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Apr 15, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
Vexu added a commit to Vexu/zig that referenced this issue Oct 6, 2022
Vexu added a commit to Vexu/zig that referenced this issue Oct 7, 2022
@Vexu Vexu closed this as completed in 29ae651 Oct 10, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.10.0 Oct 11, 2022
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted This proposal is planned. frontend Tokenization, parsing, AstGen, Sema, and Liveness. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

2 participants