避免编译警告"clauses with the same name and arity (number of arguments) should be grouped together"

Avoid compile warning "clauses with the same name and arity (number of arguments) should be grouped together"

我目前正在做一个 Elixir 项目,用 Mix 编译,有很多 clauses with the same name and arity (number of arguments) should be grouped together 警告。问题是不把它组合在一起是一种选择(出于逻辑原因),所以我试图找到一种方法来消除这种类型的警告。

我做了一些研究,我了解了 @compile 属性,它允许静音一些警告,例如 :nowarn_unused_vars,但是由于 "same name and arity group" 警告接缝是一个 Elixir 警告,所以不能这样静音,所以我正在寻找另一种无需移动函数的解决方案。

感谢您的帮助。

我相信答案是你不能。

回顾 2015 年在 Elixir Google 组中的讨论:How do you disable specific warnings

何塞:

Honestly, releasing/deploying code with warnings is not an option in my book. The reason we emit warnings instead of errors is because there is no reason to make your compilation fail right out of the box, better to collect the warnings and show them for all files, instead of have the frustrating process of fixing one error just for another one to show up. That's also why we don't plan to provide options for disabling warnings: they should be fixed, even if they don't error out upfront.

线程中有一个建议的折衷方案,可能 为您工作,同时将您想要的功能分组:

  def event(:x, var), do: one_thing(var) 
  def event(:y, var), do: another_thing(var) 
  def event(:z, var), do: something_else_entirely(var) 

祝你好运!