Skip to content

defmacrop doesn't work without parenthesis after Elixir 1.15 #13411

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

Closed
petrkozorezov opened this issue Mar 13, 2024 · 1 comment
Closed

defmacrop doesn't work without parenthesis after Elixir 1.15 #13411

petrkozorezov opened this issue Mar 13, 2024 · 1 comment

Comments

@petrkozorezov
Copy link

petrkozorezov commented Mar 13, 2024

Elixir and Erlang/OTP versions

Erlang/OTP 25 [erts-13.2.2.5] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Elixir 1.15.7 (compiled with Erlang/OTP 25)

Operating system

Linux asrock-x300 6.1.71 #1-NixOS SMP PREEMPT_DYNAMIC Fri Jan 5 14:18:41 UTC 2024 x86_64 GNU/Linux

Current behavior

Corrected example of private macros doesn't work in Elixir 1.15 (but works in 1.14)

iex(1)> defmodule Sample do
...(1)>  defmacrop two, do: 2
...(1)>  def four, do: two + two
...(1)> end
error: undefined variable "two"
  iex:9: Sample.four/0

error: undefined variable "two"
  iex:9: Sample.four/0

warning: macro two/0 is unused
  iex:8: Sample (module)

** (CompileError) iex: cannot compile module Sample (errors have been logged)
    (elixir 1.15.7) elixir_module.erl:182: anonymous fn/9 in :elixir_module.compile/7
    iex:7: (file)

But it works with parenthesis

iex(1)> defmodule Sample do
...(1)>  defmacrop two, do: 2
...(1)>  def four, do: two() + two()
...(1)> end

{:module, Sample,
 <<70, 79, 82, 49, 0, 0, 5, 124, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 169,
   0, 0, 0, 17, 13, 69, 108, 105, 120, 105, 114, 46, 83, 97, 109, 112, 108, 101,
   8, 95, 95, 105, 110, 102, 111, 95, 95, ...>>, {:four, 0}}
iex(2)> Sample.four
4

Expected behavior

Private macro without parenthesis should work.

@petrkozorezov petrkozorezov changed the title Private macros doesn't work without parenthesis after Elixir 1.15 defmacrop doesn't work without parenthesis after Elixir 1.15 Mar 13, 2024
@josevalim
Copy link
Member

I will fix the documentation. There is a flag to enable the old behaviour, if desired: see :on_undefined_variable. I will fix the example.

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