Skip to content

IO.warn diagnostic with not filled metadata #13179

@lukaszsamson

Description

@lukaszsamson

Elixir and Erlang/OTP versions

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

Elixir 1.16.0-rc.1 (81a12b7) (compiled with Erlang/OTP 26)

Operating system

macOS

Current behavior

Repro:

  1. Create an empty mix project
  2. Add IO.warn("foo") in mix.exs
  3. in iex
Mix.start()
Code.with_diagnostics(fn -> Code.compile_file("mix.exs") end)
   %{
     message: "foo",
     position: 0,
     file: nil,
     stacktrace: [
       {:elixir_compiler_0, :__FILE__, 1, [file: ~c"mix.exs", line: 57]},
       {:elixir_compiler, :dispatch, 4,
        [file: ~c"src/elixir_compiler.erl", line: 67]},
       {:elixir_compiler, :compile, 4,
        [file: ~c"src/elixir_compiler.erl", line: 52]},
       {:elixir_compiler, :maybe_fast_compile, 3,
        [file: ~c"src/elixir_compiler.erl", line: 39]},
       {:elixir_lexical, :run, 3, [file: ~c"src/elixir_lexical.erl", line: 15]},
       {:elixir_compiler, :quoted, 3,
        [file: ~c"src/elixir_compiler.erl", line: 17]}
     ],
     span: nil,
     severity: :warning
   }
Mix.start()
Kernel.ParallelCompiler.compile(["mix.exs"], return_diagnostics: true)
compile_warnings: [
     %{
       message: "foo",
       position: 0,
       file: nil,
       stacktrace: [
         {:elixir_compiler_1, :__MODULE__, 1, [file: ~c"mix.exs", line: 57]},
         {:elixir_compiler, :dispatch, 4,
          [file: ~c"src/elixir_compiler.erl", line: 67]},
         {:elixir_compiler, :compile, 4,
          [file: ~c"src/elixir_compiler.erl", line: 52]},
         {:elixir_module, :eval_form, 7,
          [file: ~c"src/elixir_module.erl", line: 426]},
         {:elixir_module, :compile, 7,
          [file: ~c"src/elixir_module.erl", line: 128]},
         {:elixir_compiler_0, :__FILE__, 1, [file: ~c"mix.exs", line: 1]}
       ],
       span: nil,
       severity: :warning
     }
     ]

Similarly, if I put IO.warn in lib/sample.ex and do

Mix.start()
Code.compile_file("mix.exs")
Mix.Task.run("compile", ["--return-errors", "--force"])

the warning will be printed with file and position

warning: foo
  lib/sample.ex:2: (file)
  (elixir 1.16.0-rc.1) src/elixir_compiler.erl:67: :elixir_compiler.dispatch/4
  (elixir 1.16.0-rc.1) src/elixir_compiler.erl:52: :elixir_compiler.compile/4
  (elixir 1.16.0-rc.1) src/elixir_compiler.erl:39: :elixir_compiler.maybe_fast_compile/3
  (elixir 1.16.0-rc.1) src/elixir_lexical.erl:15: :elixir_lexical.run/3
  (elixir 1.16.0-rc.1) src/elixir_compiler.erl:17: :elixir_compiler.quoted/3

but returned diagnostic is not filled

%Mix.Task.Compiler.Diagnostic{
     file: nil,
     severity: :warning,
     message: "foo",
     position: 0,
     compiler_name: "Elixir",
     span: nil,
     details: nil,
     stacktrace: [
       {:elixir_compiler_0, :__FILE__, 1, [file: ~c"lib/sample.ex", line: 2]},
       {:elixir_compiler, :dispatch, 4,
        [file: ~c"src/elixir_compiler.erl", line: 67]},
       {:elixir_compiler, :compile, 4,
        [file: ~c"src/elixir_compiler.erl", line: 52]},
       {:elixir_compiler, :maybe_fast_compile, 3,
        [file: ~c"src/elixir_compiler.erl", line: 39]},
       {:elixir_lexical, :run, 3, [file: ~c"src/elixir_lexical.erl", line: 15]},
       {:elixir_compiler, :quoted, 3,
        [file: ~c"src/elixir_compiler.erl", line: 17]}
     ]
   }

Expected behavior

position and file properties populated

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