gpt4 book ai didi

elixir - 如何应对分组警告?

转载 作者:行者123 更新时间:2023-12-02 20:01:13 25 4
gpt4 key购买 nike

有几个 def 组,当我写 @spec 时,它会收到 warning: clauses for the same def should be grouped together, def foo/2 was previously defined 警告。 。有什么解决办法吗?

虽然警告很有用,但我想让它忽略@spec。

@spec foo(:id, integer) :: {:not_found} | {:ok, String.t}
def foo(:id, id) do
# some logic
end

@spec foo(:email, String.t) :: {:not_found} | {:ok, String.t}
def foo(:email, email) do
# some logic
end

最佳答案

@spec foo(:id, integer) :: {:not_found} | {:ok, String.t}
@spec foo(:email, String.t) :: {:not_found} | {:ok, String.t}

def foo(:id, id) do
# some logic
end

def foo(:email, email) do
# some logic
end

或者您可以使用单个规范

@spec foo(:id | :email, integer | String.t) :: {:not_found} | {:ok, String.t}

我还没有测试过,但它应该可以工作。

关于elixir - 如何应对分组警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38094236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com