Skip to content

Ambigous definition of Macro.underscore/1 #13739

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
up2jj opened this issue Jul 26, 2024 · 1 comment
Closed

Ambigous definition of Macro.underscore/1 #13739

up2jj opened this issue Jul 26, 2024 · 1 comment

Comments

@up2jj
Copy link

up2jj commented Jul 26, 2024

Elixir and Erlang/OTP versions

1.16.2, OTP-26

Operating system

Mac

Current behavior

Macro.underscore/1 takes as argument either an atom or a string:

@spec underscore(module() | atom() | String.t()) :: String.t()
  def underscore(atom_or_string)

Looking at the function definition, atom must be associated with module:

def underscore(atom) when is_atom(atom) do
    "Elixir." <> rest = Atom.to_string(atom)
    underscore(rest)
  end

We cannot therefore pass nil, which is also an atom after all:

iex(1)> Macro.underscore(nil)
** (MatchError) no match of right hand side value: "nil"
    (elixir 1.13.0) lib/macro.ex:1840: Macro.underscore/1

Should atoms that are not associated with modules be supported somehow by Macro.underscore/1?

Expected behavior

To be discussed

@josevalim
Copy link
Member

A module is just an atom as well, :foo is a valid after all. So the spec is redundant, we need to fix it as well as the docs.

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