Skip to content

Unhandled format in elixir_erl_compiler:format_errors/1 throws argument error #10436

Closed
@marianoguerra

Description

@marianoguerra

Precheck

  • Do not use the issue tracker for help or support (try Elixir Forum, Stack Overflow, IRC, etc.)
  • For proposing a new feature, please start a discussion on the Elixir Core mailing list: https://groups.google.com/group/elixir-lang-core
  • For bugs, do a quick search and make sure the bug has not yet been reported
  • Please disclose security vulnerabilities privately at elixir-security@googlegroups.com
  • Finally, be nice and have fun!

Environment

  • Elixir & Erlang/OTP versions (elixir --version):
Erlang/OTP 23 [erts-11.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]
Elixir 1.10.4 (compiled with Erlang/OTP 23)
  • Operating system: Ubuntu 20.04

Current behavior

Include code samples, errors and stacktraces if appropriate.

When compiling the following code with elixirc mymod.ex

defmodule MyMod do
  def f(r) when :erlang.is_record(r, :my_record) do
    :ok
  end
end

This error is printed:

== Compilation error in file mymod.ex ==
** (ArgumentError) argument error
    (stdlib 3.13.2) :unicode.characters_to_binary(MyMod)
    (elixir 1.10.4) src/elixir_utils.erl:125: :elixir_utils.characters_to_binary/1
    (elixir 1.10.4) src/elixir_erl_compiler.erl:76: anonymous fn/1 in :elixir_erl_compiler.format_errors/1
    (stdlib 3.13.2) lists.erl:1342: :lists.foreach/2
    (elixir 1.10.4) src/elixir_erl_compiler.erl:12: anonymous fn/3 in :elixir_erl_compiler.spawn/2

Tracing the call:

:dbg.start()
:dbg.tracer()
:dbg.p(:all, :c)
:dbg.tpl(:elixir_erl_compiler, :format_errors, 1, [{:"_", [], [{:return_trace}]}])
Elixir.Kernel.ParallelCompiler.compile(["mymod.ex"])

Shows this format:

elixir_erl_compiler:format_errors([{'Elixir.MyMod',[{none,core_lint,{illegal_guard,{f,1}}}]}])

Expected behavior

Either the elixir compiler rejecting the guard if it makes sense or changing

BinFile = elixir_utils:characters_to_binary(File),

To something like Source = format_error_source(File) that handles atoms.

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