dlang-community / D-Scanner

Swiss-army knife for D source code
Boost Software License 1.0
239 stars 80 forks source link

Error: variable `s` is shadowing variable is not found by dscanner #785

Open andre2007 opened 4 years ago

andre2007 commented 4 years ago

While dmd abort compilation, D-Scanner does not find this issue:

As this error only occurs while compiling with version CRuntime_Musl, it would be good if D-Scanner can find it.

root/.dub/packages/arsd-official-4.4.0/arsd-official/cgi.d(3357,10): Error: variable s is shadowing variable arsd.cgi.cgiMainImpl!(handle, Cgi, 5000000L).cgiMainImpl.s root/.dub/packages/arsd-official-4.4.0/arsd-official/cgi.d(3380,10): Error: variable s is shadowing variable arsd.cgi.cgiMainImpl!(handle, Cgi, 5000000L).cgiMainImpl.s tmp/app.d(12,5): Error: template instance arsd.cgi.cgiMainImpl!(handle, Cgi, 5000000L) error instantiating

See also issue for solving the issue here https://github.com/adamdruppe/arsd/issues/232

WebFreak001 commented 4 years ago

D-Scanner already covers this:

void main() {
    int x;
    int x;
    int y;
}

stdin(3:5)[warn]: Variable "x" has the same name as a variable defined on line 2.

sometimes it's overly eager but that's not the problem here.

Can you make a reproducible case when it doesn't happen for your code?

andre2007 commented 4 years ago

I am not sure whether this minimized is correct, but it shows the problem:

import std;

void main() {
    int x;

    version(CRuntime_Musl) {
        auto x = "vvv";
            stderr.writeln(x);
    } else {
    stderr.writeln(x);
    }
}

dscanner --report t1.d shows these findings:

{
  "issues": [
    {
      "key": "dscanner.suspicious.unmodified",
      "fileName": "t1.d",
      "line": 5,
      "column": 9,
      "message": "Variable x is never modified and could have been declared const or immutable."
    },
    {
      "key": "dscanner.suspicious.unused_variable",
      "fileName": "t1.d",
      "line": 5,
      "column": 9,
      "message": "Variable x is never used."
    },
    {
      "key": "dscanner.suspicious.unmodified",
      "fileName": "t1.d",
      "line": 10,
      "column": 10,
      "message": "Variable x is never modified and could have been declared const or immutable."
    }
  ],
  "interfaceCount": 0,
  "classCount": 0,
  "functionCount": 1,
  "templateCount": 0,
  "structCount": 0,
  "statementCount": 4,
  "lineOfCodeCount": 5,
  "undocumentedPublicSymbols": 0
}