This patch allows fixing PR39583.
- add unit test
as discussed on IRC making it an AST_POLYMORPHIC_MATCHER_P does not seem to work, as the polymorphism is only in the return type. We do need the Node itself to be polymorphic (same type as returntype). The only working version I got was using the overloads.
Adding a few other reviewers in case they have ideas on how to use the polymorphic matcher rather than the overload. If they don't have a better idea, then I think the overload approach is fine.
You can't use AST_POLYMORPHIC_MATCHER_P to overload on input types.