elixir-lang / elixir

Elixir is a dynamic, functional language for building scalable and maintainable applications
https://elixir-lang.org/
Apache License 2.0
24.51k stars 3.38k forks source link

Warning of unused variables are printed in reverse order when within the same line #9344

Closed eksperimental closed 5 years ago

eksperimental commented 5 years ago

Environment

Current behavior

when variables are unused in the same line, the order of the warnings is given in reverse

      pmfa = {prefix, original_module, function, arity} = split_match(:module, match)
warning: variable "arity" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/ex_doc/formatter/html/autolink.ex:402: ExDoc.Formatter.HTML.Autolink.replace_fun/4

warning: variable "function" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/ex_doc/formatter/html/autolink.ex:402: ExDoc.Formatter.HTML.Autolink.replace_fun/4

warning: variable "prefix" is unused (if the variable is not meant to be used, prefix it with an underscore)
  lib/ex_doc/formatter/html/autolink.ex:402: ExDoc.Formatter.HTML.Autolink.replace_fun/4

Include code samples, errors and stacktraces if appropriate.

Expected behavior

To print the warnings in the correct order

josevalim commented 5 years ago

The order is rather alphabetical:

iex(1)> defmodule Foo do
...(1)> def bar(arg) do
...(1)> {a, c, b} = arg
...(1)> end
...(1)> end
warning: variable "a" is unused (if the variable is not meant to be used, prefix it with an underscore)
  iex:3: Foo.bar/1

warning: variable "b" is unused (if the variable is not meant to be used, prefix it with an underscore)
  iex:3: Foo.bar/1

warning: variable "c" is unused (if the variable is not meant to be used, prefix it with an underscore)
  iex:3: Foo.bar/1

I am not sure if I would consider it a bug but we would need to complicate the compiler to track the order they are defined besides their name and I don't think the complexity is worth it.

Thanks for the report @eksperimental!