Skip to content

Ambigous definition of Macro.underscore/1 #13739

@up2jj

Description

@up2jj

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions