Expand macro expressions arguments before macro calls. Fixes #2388 #2392
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change makes this code:
to first expand
{{argument}}
. If it's aPath
denoting a type, aTypeNode
is passed to the macro. If it denotes a constant, the constant's value is passed to the macro. Otherwise the regular expansion is passed to it.This makes it possible to extract a repeated macro argument into a constant:
Or, following @BlaXpirit 's example you can include the constants of a type inside another type:
In fact in the above case it can also be simplified for the macro caller by using a second macro, because the expected argument is always expected to be a type:
For this last case we might also want to make it simpler by maybe putting a
TypeNode
type restriction in the macro, so the compiler will always try to convert a Path argument to aTypeNode
so there's no need to surround it in curly braces. But this won't solve the JSON/YAML Mapping reuse, so it's still worth introducing this feature.