Skip to content

Fix expand crash on invalid multialias root #14698

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

Merged
merged 1 commit into from
Aug 6, 2025

Conversation

lukaszsamson
Copy link
Contributor

I noticed this code crashes

iex(1)> defmodule A do
...(1)> @asd Foo
...(1)> alias @asd.{Bar}
...(1)> end
** (FunctionClauseError) no function clause matching in :elixir_aliases.do_concat/2    
    
    The following arguments were given to :elixir_aliases.do_concat/2:
    
        # 1
        [
          {{:., [line: 3], [Module, :__get_attribute__]}, [line: 3], [A, :asd, 3, true]},
          :Bar
        ]
    
        # 2
        "Elixir"
    
    (elixir 1.18.4) src/elixir_aliases.erl:183: :elixir_aliases.do_concat/2
    (elixir 1.18.4) src/elixir_aliases.erl:171: :elixir_aliases.concat/1
    (elixir 1.18.4) src/elixir_expand.erl:575: anonymous fn/8 in :elixir_expand.expand_multi_alias_call/7
    (elixir 1.18.4) src/elixir_expand.erl:701: :elixir_expand.mapfold/5
    (elixir 1.18.4) src/elixir_expand.erl:625: :elixir_expand.expand_block/5
    (elixir 1.18.4) src/elixir_expand.erl:48: :elixir_expand.expand/3
    (elixir 1.18.4) src/elixir_expand.erl:13: :elixir_expand.expand/3
    iex:1: (file)

Compare to:

iex(1)> defmodule A do
...(1)> @asd Foo
...(1)> alias @asd.Bar
...(1)> end
error: invalid alias: "@asd.Bar". If you wanted to define an alias, an alias must expand to an atom at compile time but it did not, you may use Module.concat/2 to build it at runtime. If instead you wanted to invoke a function or access a field, wrap the function or field name in double quotes
└─ iex:3: A (module)

** (CompileError) iex: cannot compile module A (errors have been logged)
    (elixir 1.18.4) src/elixir_expand.erl:71: :elixir_expand.expand/3
    (elixir 1.18.4) src/elixir_expand.erl:625: :elixir_expand.expand_block/5
    (elixir 1.18.4) src/elixir_expand.erl:48: :elixir_expand.expand/3
    (elixir 1.18.4) src/elixir_expand.erl:13: :elixir_expand.expand/3
    (elixir 1.18.4) src/elixir_expand.erl:634: :elixir_expand.expand_block/5
    (elixir 1.18.4) src/elixir_expand.erl:48: :elixir_expand.expand/3
    iex:1: (file)

@josevalim josevalim merged commit 75a3272 into elixir-lang:main Aug 6, 2025
12 of 13 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

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

Successfully merging this pull request may close these issues.

2 participants