Using core.reflect to check for unused parameters
user1234
user1234 at 12.de
Fri Sep 3 16:02:18 UTC 2021
On Friday, 3 September 2021 at 15:47:16 UTC, Stefan Koch wrote:
> 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);`
indeed I've missed that line
> 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.
Yes and no. It's better _as example_, so that we can see clearly
that params are marked on use. Basically my first answer was
posted because overridding the visit of VarDecl was confusing.
Otherwise that looks like a convincing example.
More information about the Digitalmars-d
mailing list