Spec for Minimal Length Binary Type

Dialyzer is telling me that an output looks like:

{'error',<<_:48,_:_*8>>}

which I see means that the binary is at least 48 bits long

http://learnyousomeerlang.com/dialyzer

how can I specify this in a Elixir type spec?

2 Likes

Per the docs:

type :: :atom                         ## Atoms
      | 1                             ## Integers
      | 1..10                         ## Integers from 1 to 10
      | 1.0                           ## Floats

   | <<>>                          ## Bitstrings
   | <<_ :: size>>                 # size is 0 or a positive integer
   | <<_ :: _ * unit>>             # unit is an integer from 1 to 256
   | <<_ :: size * unit>>

you can read about it here.

2 Likes

I just noticed that too, but

<<_ :: 48, _ :: _*8>>

doesn’t work

What exactly do you mean, wiritng „doesn’t work”?

1 Like

Dialyzer returns this error:

** (CompileError) lib/xoxo.ex:41: type '*'(_,_) undefined

I played a bit with it.

defmodule Diafoo do
  @spec foo(<<_ :: 48, _ :: _ * 8>>) :: 4
  def foo(_a), do: 4
end

The module above can be checked when using elixir master, but not on elixir 1.2.5. Also it seems to be independent of OTP version and I used dialyze-packaeg to wrap dialyzer.

So it seems as if there is something in the current elixir compiler blocking this.

@josevalim is there any chance to backport?

Backported, thank you. We should have v1.2.6 out soon (as soon as a new RC for Erlang 19 is out).

thanks guys - appreciate it