How to type a function returning an Erlang type?

I have this function and spec:

  @spec new_queue() :: tuple
  defp new_queue, do: :queue.new

The function simply instantiates an erlang queue which is just a tuple in elixir. But when running dyalixir, it fails because:

The @spec for MyModule.new_queue/0 has an opaque
subtype :queue.queue(_) which is violated by the success typing.

Success typing:
() :: :queue.queue(_)

I’m not sure how to type this now

The :queue module declares its data as opaque, so Dialyzer will give you this error unless you use the opaque type - either :queue.queue() or :queue.queue(element_type)

4 Likes