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

False positives for unused variable #46

Open
nordlow opened this issue Nov 14, 2022 · 0 comments
Open

False positives for unused variable #46

nordlow opened this issue Nov 14, 2022 · 0 comments

Comments

@nordlow
Copy link
Contributor

nordlow commented Nov 14, 2022

The current diagnostics of unused variables is incomplete and gives false positives because it doesn't take into account the possibility of values passed to a ref-parameter of a function f can being mutated inside the f. For instance

void inc(T)(ref T x) {
    x =+ 1;
}

@safe pure unittest {
    int x = 1;
    inc(x);
    assert(x == 2);
}

gives warning

Variable x is never modified and could have been declared const or immutable.

but shouldn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant