svetigrah

svetigrah

Greetings. I have a problem with dialyxir (0.5, elixir 1.5).
The usecase is this:

from(x in SomeModule)
|> function1()
|> function2()
|> limit(10)
|> function3()

I want to give the functions @specs, but here’s the problem:
@spec function1(Ecto.Query.t) :: Ecto.Query.t raises a dialyzer error:

The call 'Elixir.Pop.Search':add_tag_filters(#{'__struct__':='Elixir.Ecto.Query', 'assocs':=[], 'distinct':='nil', 'from':={'nil' | <<_:64>> | ['author' | 'author_id' | 'contents' | 'id' | 'inserted_at' | 'is_disabled' | 'is_pending' | 'l10n' | 'search'
 | 'tag_ids' | 'type' | 'updated_at' | {'inserted_at',{'Elixir.Ecto.Schema','__timestamps__',[any(),...]}} | {'updated_at',{'Elixir.Ecto.Schema','__timestamps__',[any(),...]}}] | 130233438 | {'id','id'} | #{'__struct__'=>'Elixir.Ecto.Query', 'assocs'=>[], 'author_id'=>'id', 'contents
'=>'map', 'distinct'=>'nil', 'from'=>{<<_:64>>,'Elixir.Pop.Library.Resource'}, 'group_bys'=>[], 'havings'=>[], 'id'=>'id', 'inserted_at'=>'utc_datetime', 'is_disabled'=>'boolean', 'is_pending'=>'boolean', 'joins'=>[], 'l10n'=>{'array','map'}, 'limit'=>'nil', 'lock'=>'nil', 'offset'=>
'nil', 'order_bys'=>[], 'prefix'=>'nil', 'preloads'=>[], 'search'=>'map', 'select'=>'nil', 'sources'=>'nil', 'tag_ids'=>{'array','integer'}, 'type'=>'string', 'updated_at'=>'utc_datetime', 'updates'=>[], 'wheres'=>[]},'Elixir.Pop.Library.Resource'}, 'group_bys':=[], 'havings':=[], 'j
oins':=[], 'limit':='nil', 'lock':='nil', 'offset':='nil', 'order_bys':=[], 'prefix':='nil' | <<_:64>> | ['author' | 'author_id' | 'contents' | 'id' | 'inserted_at' | 'is_disabled' | 'is_pending' | 'l10n' | 'search' | 'tag_ids' | 'type' | 'updated_at' | {'inserted_at',{'Elixir.Ecto.S
chema','__timestamps__',[any(),...]}} | {'updated_at',{'Elixir.Ecto.Schema','__timestamps__',[any(),...]}}] | 130233438 | {'id','id'} | #{'__struct__'=>'Elixir.Ecto.Query', 'assocs'=>[], 'author_id'=>'id', 'contents'=>'map', 'distinct'=>'nil', 'from'=>{<<_:64>>,'Elixir.Pop.Library.Re
source'}, 'group_bys'=>[], 'havings'=>[], 'id'=>'id', 'inserted_at'=>'utc_datetime', 'is_disabled'=>'boolean', 'is_pending'=>'boolean', 'joins'=>[], 'l10n'=>{'array','map'}, 'limit'=>'nil', 'lock'=>'nil', 'offset'=>'nil', 'order_bys'=>[], 'prefix'=>'nil', 'preloads'=>[], 'search'=>'m
ap', 'select'=>'nil', 'sources'=>'nil', 'tag_ids'=>{'array','integer'}, 'type'=>'string', 'updated_at'=>'utc_datetime', 'updates'=>[], 'wheres'=>[]}, 'preloads':=[], 'select':='nil', 'sources':='nil', 'updates':=[], 'wheres':=[#{'__struct__':='Elixir.Ecto.Query.BooleanExpr', 'expr':=
{'and',[],[{'==',[],[{{'.',[],['is_disabled' | 'is_pending' | {'&',[],[0,...]},...]},[],[]} | #{'__struct__':='Elixir.Ecto.Query.Tagged', 'tag':='nil', 'type':={0,'is_disabled' | 'is_pending'}, 'value':='false'},...]},...]}, 'file':=<<_:432>>, 'line':=10, 'op':='and', 'params':=[]},.
..]},tags@1::any()) does not have an opaque term of type 'Elixir.Ecto.Query':t() as 1st argument

This won’t happen with function2 though:
@spec function2(Ecto.Query.t) :: Ecto.Query.t
but will happen again with function3:
@spec function3(Ecto.Query.t) :: Ecto.Query.t

Note that functions alter query in a way, say, pipe it through where or whatever.

Any idea why the first and third @specs aren’t good?

First 9 of 9 Posts Switch mode

NobbZ

NobbZ

From is a macro and creates a literal of the struct, therefore dialyzer sees the opacity violated. Limit is a macro as well and makes dialyzer think you were fiddling with the internals of the struct on your own, therefore it seems opacity violated.

svetigrah

svetigrah OP

Why is @spec for function2 valid then, if it uses a macro as well in its function body, e.g where(query, ....).
Actually, this is the same for function1’s return value as well, as this is valid: @spec function1(any()) :: Ecto.Query.t.

NobbZ

NobbZ

The specs for your functions seem to be valid, dialyzer complains about the calls.

x = from …
y = x
|> function1()
|> function2()
|> limit(10)

function3(y)

will probably be fine.

Unless you are running the query in function3/1, you can also swap the ordering:

x = from …
x
|> function1()
|> function2()
|> function3()
|> limit(10)
svetigrah

svetigrah OP

Unfortunately, this does not solve the issue, error messages remain the same.

NobbZ

NobbZ

I think I can see why it doesn’t for function1… But it remains for 3 as well when reordering calls?

svetigrah

svetigrah OP

Oh, sorry, yes, it does work for 3, because of reordering.

NobbZ

NobbZ

I have taken the freedom to actually post a bug report at ecto:

https://github.com/elixir-ecto/ecto/issues/2151

svetigrah

svetigrah OP

Nice, thanks.

NobbZ

NobbZ

It got fixed today, so once the next version gets released it should be fine.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement