-
Notifications
You must be signed in to change notification settings - Fork 457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix modifyAllMatching visitor helper #5020
Conversation
@@ -820,7 +820,7 @@ const RootType *modifyAllMatching(const RootType *root, Func &&function) { | |||
Func function; | |||
void postorder(NodeType *node) override { function(node); } | |||
}; | |||
return root->apply(NodeVisitor(std::forward<Func>(function))); | |||
return root->apply(NodeVisitor(std::forward<Func>(function)))->template checkedTo<RootType>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
template
keyword needed as the RootType
is a type parameter
56ff647
to
b671a45
Compare
Signed-off-by: Vladimír Štill <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the point it to allow this to be called on nodes that are not expected to be root nodes and don't define an apply
overload with covariant return type (don't have #apply
in the .def file)? Seems like a rare corner case.
Yes. For example a |
A very simple fix of
P4::modifyAllMatching
visitor helper. Basically while theModifier
visitor guarantees that the result type of node transformation is the same as the original, theapply
function type cannot reflect that as it has to be able to work with any visitor. Therefore,modifyAllMatching
needs an explicit cast, otherwise it would work only onRootType = IR::Node
.