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

Macro.to_string/2 hard deprecated with no suitable replacement #11373

Closed
lukaszsamson opened this issue Nov 7, 2021 · 2 comments
Closed

Macro.to_string/2 hard deprecated with no suitable replacement #11373

lukaszsamson opened this issue Nov 7, 2021 · 2 comments

Comments

@lukaszsamson
Copy link
Contributor

Environment

  • Elixir & Erlang/OTP versions (elixir --version):
    Erlang/OTP 24 [erts-12.1.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
    Elixir 1.13.0-rc.0 (48b838a) (compiled with Erlang/OTP 24)
  • Operating system: macOS

Current behavior

Macro.to_string(expr, &modify_codegen/2)
warning: Macro.to_string/2 is deprecated. Use Macro.to_string/1 instead
  lib/erl2ex/pipeline/codegen.ex:505: Erl2ex.Pipeline.Codegen.expr_to_string/1

There is no suitable replacement (or the docs are missing) for code that used Macro.to_sting/2 with custom changes to code output. Clearly Macro.to_string/1 cannot be used instead.

Expected behavior

No deprecation or otherwise a suitable warning pointing to how a similar effect can be achieved with Inspect.Algebra.format and Code.quoted_to_algebra. An example in Code.quoted_to_algebra docs would also help.

@josevalim
Copy link
Member

josevalim commented Nov 7, 2021

We have replaced it on ExDoc and Ecto. The approaches are usually by doing a pre-pass on the data or a post-pass on the output. From a quick look at erl2ex, you could do a prewalk that matches on {:?, metadata, Elixir} and return a new variable that will be printed as is. If that's not enough, then please expand and I will be glad to help find a solution. In the worst case scenario you can part the Macro.to_string functionality. :)

Thanks for the reports btw!

@lukaszsamson
Copy link
Contributor Author

Yep, doing a prewalk is always an option.

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

No branches or pull requests

2 participants