Skip to content
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

Refactor router macros to limit compile-time dependencies #547

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

xpgdk
Copy link

@xpgdk xpgdk commented Jan 10, 2024

Updated to apply cleanly

case Keyword.get(opts, :prefix) do
nil ->
nil
{opts, _bindings} = Code.eval_quoted(opts, [], __CALLER__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hex docs for the Code.eval_quoted/3 function has the following warning which seems to be applicable here as the usage is within a macro.

Warning: Calling this function inside a macro is considered bad practice as it will attempt to evaluate runtime values at compile time. Macro arguments are typically transformed by unquoting them into the returned quoted expressions (instead of evaluated).

I don't know what this code is supposed to be doing or why it is needed. The macros in this module are already difficult enough to understand without this added complexity.

Can you help me (and other contributors to this code) to understand what is going on.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted. I think I managed to rewrite the macro to avoid using eval_quoted.
It was needed to properly handle the case where a function-reference is passed to the by option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants