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

lifting from within user-defined macros can break compilation #141

Open
novaugust opened this issue Mar 19, 2024 · 0 comments
Open

lifting from within user-defined macros can break compilation #141

novaugust opened this issue Mar 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@novaugust
Copy link
Contributor

novaugust commented Mar 19, 2024

Versions

currently on main, but 0.12 when it gets cut

Example Input

lifting is smart enough to not interact with quote children, but user-defined macros can hide that that's occurring.

defmodule Foo do
  @moduledoc false

  my_quote do
    alias AliasFor.In.MyQuote

    ... Foo.Bar.Baz... 
    ... Foo.Bar.Baz ...
  end
end

results in:

defmodule Foo do
  @moduledoc false
  alias Foo.Bar.Baz

  my_quote do
    alias AliasFor.In.MyQuote

    ... Baz... 
    ... Baz ...
  end
end

but as with quote, the compiler will warn that Baz is unused within Foo, and anything that uses my_quote will then error on Baz being undefined

as-is, the user will have to put the alias where it belongs inside my_quote, which styler is just fine with and will leave be. still, i'd like styler to not leave a codebase uncompilable, even if it just requires a simple human fix

Fix

I see two possible

  1. never go into do blocks of unknown parents looking for liftable aliases (allowlist all kernel forms and nothing else)
  2. when a do-block contains a module directive, assume that it's equivalent to a quote block and back out of it

there are pros and cons to each, but 2 probably gives the more correct result, with the downside being a more complex look-ahead implementation. actually, the real win might be doing a combination of both: when encounter directives in a nested scope, figure out if it's a known block parent. if it is, carry on. if it's not, assume this works as a quote does and don't lift

@novaugust novaugust added the bug Something isn't working label Mar 19, 2024
@novaugust novaugust changed the title lifting outside of user-defined macros can break scoping lifting from within user-defined macros can break compilation Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant