Open kshyatt opened 6 months ago
Wrapping an argument in @nospecialize
also causes semgrep
to whine
In the first example, the problem is caused by how Semgrep parses the list comprehension. If you write only the comprehension in a file ([c^2 for c in b]
), say test.jl
, and run semgrep scan --dump-ast -l julia test.jl
you'll see this AST:
Pr(
[ExprStmt(
Comprehension(Array,
(Call(IdSpecial((Op(Pow), ())),
[Arg(
N(
Id(("c", ()),
{id_info_id=1; id_flags=Ref(0); id_resolved=Ref(None);
id_type=Ref(None); id_svalue=Ref(None); })));
Arg(L(Int((Some(2), ()))))]),
[])), ())])
There is no information about the iteration variable or the iterator. So there's no way to know that b
, the iterator in this case, is unused. It might not be the only example of this. Maybe you found more in the meantime? I could file an issue on Semgrep with more general examples.
The second example (with ::Val{true}
) now works for me with Semgrep 1.81.0 (the latest is 1.84).
And the last one is again a parsing problem. Semgrep doesn't think the syntax is correct. I'm not sure if the problem comes from the Julia tree-sitter or from the generic AST generated by Semgrep.
Updates:
@nospecialize
case.
will cause
semgrep
to error with the current rules sayingb
is unused.Similarly,
Val
types used to dispatch (or any::Type{SomeType}
) arguments cause unused parameter errors:this will generate an error saying
::Val{true}
is unused.