简体   繁体   English

Dialyxir错误order_by不返回Ecto.Query.t

[英]Dialyxir error order_by doesnt return Ecto.Query.t

I have this method 我有这种方法

@spec modify_query(Ecto.Query.t) :: Ecto.Query.t
def modify_query(query) do
  # modifies a Ecto.Query.t
end

Then I chain that method with a query: 然后,我将该方法与查询链接起来:

Item
|> where([active: true])
|> order_by([desc: :start])
|> modify_query

The code works correctly but apparently for dialyzer order_by is not returning a Ecto.Query.t because it complains with: 该代码正常工作,但显然对于dialyzer order_by没有返回Ecto.Query.t因为它抱怨:

The call 'modify_query'... does not have a term of type atom() | 调用'modify_query'...没有类型为atom()的术语| 'Elixir.Ecto.Query':t() (with opaque subterms) as 1st argument 'Elixir.Ecto.Query':t()(具有不透明的子术语)作为第一个参数

If I comment out # |> order_by([desc: :start]) then dialyzer doesnt complain 如果我注释掉# |> order_by([desc: :start])dialyzer不会抱怨

I have tested through iex the output of: 我已经通过iex测试了以下输出:

Item
|> where([active: true])
|> order_by([desc: :start])

and it says it's data type is Ecto.Query: 它说它的数据类型是Ecto.Query:

Term                                                                         
  #Ecto.Query<from r in Item, where: r.active == true, order_by: [desc: r.start]>
Data type                                                                    
  Ecto.Query

So how can dialyzer complains?? 那么透析器怎么抱怨呢?

More info here https://elixirforum.com/t/dialyxir-error-when-using-ecto-query-t-as-function-argument/7491 更多信息在这里https://elixirforum.com/t/dialyxir-error-when-using-ecto-query-t-as-function-argument/7491

Basically, order_by is a macro and dialyxir complains about an opaque type. 基本上,order_by是宏,而Dialyxir抱怨不透明的类型。

I think it's fixed in recent versions of Ecto but if you have this issue in older versions of Ecto you can fix it by swapping the calls: 我认为它在Ecto的最新版本中已解决,但是如果您在Ecto的较早版本中存在此问题,则可以通过交换调用来解决此问题:

Item
|> order_by([desc: :start])
|> where([active: true])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM