忽略透析仪警告生成的代码

时间:2018-08-22 15:53:58

标签: elixir dialyzer

我正在尝试使我的用于处理结果元组的库(https://github.com/CrowdHailer/OK)与透析器配合良好。

此时,如果给出了错误的数据输入,则有一些代码会引发一个错误。但是透析器指出这种情况是不需要的。我仍然想保留这种错误情况。向该库的新用户解释该错误非常有帮助,但我想让透析器忽略该错误。

quote location: :keep do
  case unquote(right) do
    {:ok, unquote(left)} ->
      unquote(expand_bindings(rest, yield_block, exception_clauses))

    {:error, reason} ->
      {:error, reason}

      case reason do
        unquote(exception_clauses)
      end

      # This block will never be called, as far as dialyzer is concerned
      # However I want to keep it for the cases when diayzer is not being used in the project
      return ->
        raise %OK.BindError{
          return: return,
          lhs: unquote(Macro.to_string(left)),
          rhs: unquote(Macro.to_string(right))
        }
  end
end

在这里https://github.com/CrowdHailer/OK/blob/431142204794e1702271c86d6594ce76b8978b57/lib/ok.ex#L512-L529

1 个答案:

答案 0 :(得分:0)

generated: true传递到quote

quote location: :keep, generated: true do

这告诉编译器和透析器不针对该代码发出警告。