lifting from within user-defined macros can break compilation

Aperta
#141 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
elixir
Ambito
tooling

Direzione di ricerca

Inizia riproducendo l’Example Input su main e verifica come styler solleva gli aliases attraverso do-blocks annidati e gestisce i quote children. Confronta le due correzioni proposte, quindi verifica che il codice che usa una macro definita dall’utente continui a compilare senza un alias esterno non utilizzato o un nome non definito all’interno della macro.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Elixir
Stelle
810
Fork
46
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Issue simili

Altre issue su Elixir

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.