2

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

如果给出不正确的数据输入,此时有代码会引发一个很好的错误。然而,dialyzer 指出,这种情况是不需要的。我仍然想保留这个错误案例。向图书馆的新用户解释错误非常有帮助,但我想让透析器忽略它。

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

4

1 回答 1

2

传递generated: truequote

quote location: :keep, generated: true do

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

于 2018-08-23T08:44:36.787 回答