dlang-community / D-Scanner

Swiss-army knife for D source code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

andy-hanson opened this issue · comments

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;
}