Using core.reflect to check for unused parameters

Stefan Koch uplink.coder at googlemail.com
Fri Sep 3 15:47:16 UTC 2021


On Friday, 3 September 2021 at 15:32:59 UTC, user1234 wrote:
> On Friday, 3 September 2021 at 14:45:20 UTC, Stefan Koch wrote:
>> On Friday, 3 September 2021 at 13:02:37 UTC, user1234 wrote:
>>> On Thursday, 2 September 2021 at 21:27:33 UTC, Stefan Koch 
>>> wrote:
>>>> [...]
>>>> now this visitor will reliably detect usage of parameters.
>>>
>>> BTW, I'm curious to know how this can work. Should not VarExp 
>>> (and not VarDecl) be overridden to mark ?
>>
>> VerExps have a VarDecl member.
>> which the transitive visitor looks into for you.
>>
>> You could look at VarExps but I chose to look into VarDecls 
>> instead.
>
> so FuncDeclaration parameters are not visited, that's why that 
> works ?
> only bodies are visited ?

Exactly this works because of this line.
`(cast()fd.fbody).accept(marker);`
I am starting the visitor at the body of the function.
And since there no back-edge to the function declaration it works.
If you have a back-edge to the function declaration for example 
in recursive call it would stop working.
So visiting the VarExp is a better idea.



More information about the Digitalmars-d mailing list