dlang-community / D-Scanner

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

Variable in a lambda template argument is considered an export by `--ctags` #867

Open andy-hanson opened 2 years ago

andy-hanson commented 2 years ago

In the following example, y is treated as an export, even though it's a local variable like b.

import core.stdc.stdio : printf;

void main() { printf("result is %d\n", foo(10)); }

alias foo = fooMaker!((int x) {
    int y = x + 1;
    return y;
});

int fooMaker(alias cb)(int a) {
    int b = a + 1;
    return cb(b);
}

If I run dub run dscanner -- --ctags a.d, I get:

!_TAG_FILE_FORMAT   2
!_TAG_FILE_SORTED   1
!_TAG_FILE_AUTHOR   Brian Schott
!_TAG_PROGRAM_URL   https://github.com/dlang-community/D-Scanner/
foo a.d 5;" a   line:5
main    a.d 3;" f   line:3  signature:()
y   a.d 6;" v   line:6

Thankfully the workaround is simple: Use a named function:

alias foo = fooMaker!fooInner;
private int fooInner(int x) {
    int y = x + 1;
    return y;
}