lifting from within user-defined macros can break compilation

Offen
#141 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
elixir
Bereich
tooling

Rechercherichtung

Beginne damit, den Example Input auf main zu reproduzieren, und untersuche, wie styler aliases durch verschachtelte do-blocks hebt und quote children behandelt. Vergleiche die beiden vorgeschlagenen Fixes und verifiziere anschließend, dass Code mit einem benutzerdefinierten Makro weiterhin kompiliert wird, ohne einen unbenutzten äußeren Alias oder einen undefinierten Namen innerhalb des Makros.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug

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

Vorherrschende Sprache
Elixir
Sterne
810
Forks
46
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Ähnliche Issues

Weitere Issues zu Elixir

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.