Skip to content

Crash when compiling a test asserting on __ENV__ #13806

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
lukaszsamson opened this issue Sep 5, 2024 · 1 comment · Fixed by #13807
Closed

Crash when compiling a test asserting on __ENV__ #13806

lukaszsamson opened this issue Sep 5, 2024 · 1 comment · Fixed by #13807

Comments

@lukaszsamson
Copy link
Contributor

Elixir and Erlang/OTP versions

Erlang/OTP 26 [erts-14.2.5.2] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]

Elixir 1.17.2 (compiled with Erlang/OTP 26)

Operating system

macOS

Current behavior

This test crashes the compiler

defmodule FooTest do
  use ExUnit.Case, async: false

  test "foo" do
    assert __ENV__ = 1
  end
end
== Compilation error in file test/foo_test.exs ==
** (FunctionClauseError) no function clause matching in :v3_core.pattern/2    
    
    The following arguments were given to :v3_core.pattern/2:
    
        # 1
        {:call, 5, {:remote, 5, {:atom, 5, :erlang}, {:atom, 5, :binary_to_term}}, [{:bin, 5, [{:bin_element, 5, {:string, 5, [131, 88, 119, 13, 110, 111, 110, 111, 100, 101, 64, 110, 111, 104, 111, 115, 116, 0, 0, 0, 247, 0, 0, 0, 0, 0, 0, 0, 0]}, :default, :default}]}]}
    
        # 2
        {:core, 3, 0, 0, {:"test foo", 1}, false, true, [extra_chunks: [{"ExCk", <<131, 104, 2, 119, 17, 101, 108, 105, 120, 105, 114, 95, 99, 104, 101, 99, 107, 101, 114, 95, 118, 49, 116, 0, 0, 0, 1, 119, 7, 101, 120, 112, 111, 114, 116, 115, 108, 0, ...>>}], debug_info: {:elixir_erl, :none}], false, [], [file: ~c"test/foo_test.exs"], false}
    
    (compiler 8.4.3) :v3_core.pattern/2
    (compiler 8.4.3) v3_core.erl:2196: :v3_core.pattern_map_pair/2
    (stdlib 5.2.3.1) lists.erl:1706: :lists.mapfoldl_1/3
    (stdlib 5.2.3.1) lists.erl:1707: :lists.mapfoldl_1/3
    (compiler 8.4.3) v3_core.erl:2190: :v3_core.pattern_map_pairs/2
    (compiler 8.4.3) v3_core.erl:2151: :v3_core.pattern/2
    (compiler 8.4.3) v3_core.erl:2357: :v3_core.pattern_list/2
    (compiler 8.4.3) v3_core.erl:303: :v3_core.clause/2
    (compiler 8.4.3) v3_core.erl:297: :v3_core.clauses/2
    (compiler 8.4.3) v3_core.erl:809: :v3_core.expr/2
    (compiler 8.4.3) v3_core.erl:2033: :v3_core.novars/2
    (compiler 8.4.3) v3_core.erl:937: :v3_core.expr/2
    (compiler 8.4.3) v3_core.erl:643: :v3_core.exprs/2
    (compiler 8.4.3) v3_core.erl:644: :v3_core.exprs/2
    (compiler 8.4.3) v3_core.erl:306: :v3_core.clause/2
    (compiler 8.4.3) v3_core.erl:297: :v3_core.clauses/2
    (compiler 8.4.3) v3_core.erl:287: :v3_core.body/4
    (compiler 8.4.3) v3_core.erl:267: :v3_core.function/3
    (compiler 8.4.3) v3_core.erl:215: :v3_core.form/3
    (stdlib 5.2.3.1) lists.erl:1599: :lists.foldl_1/3

The assert seems to be responsible. Removing it makes emit an expected error.

Expected behavior

I expect it to error with

    error: invalid pattern in match, __ENV__ is not allowed in matches
    │
  5 │     __ENV__ = 1
    │     ^
    │
    └─ test/foo_test.exs:5:5
@sabiwara
Copy link
Contributor

sabiwara commented Sep 6, 2024

Thank you for the report @lukaszsamson 💜
The issue is actually with Macro.escape/2 which bypasses the env.context != :match check, will send a PR.

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

Successfully merging a pull request may close this issue.

2 participants