TypeCheck - Fast and flexible runtime type-checking for your Elixir projects

This is a great project! Congrats on making it reality :slight_smile:

Here’s something related to what I’m working on and some of the issues I’ve run into with TypeCheck:

defmodule Sandbox do
    use TypeCheck

    @spec! foo(arg1 :: String.t(), arg2 :: String.t(), arg3 :: float) :: float

    def foo("bing", "bang", "bow") do
      # some process
  end
end
$ iex -S mix
Erlang/OTP 23 [erts-11.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Compiling 22 files (.ex)

== Compilation error in file lib/Sandbox.ex ==
** (CompileError) lib/Sandbox.ex:4: misplaced operator ::/2

The :: operator is typically used in bitstrings to specify types and sizes of segments:

    <<size::32-integer, letter::utf8, rest::binary>>

It is also used in typespecs, such as @type and @spec, to describe inputs and outputs
    (stdlib 3.13.2) lists.erl:1358: :lists.mapfoldl/3
    (stdlib 3.13.2) lists.erl:1359: :lists.mapfoldl/3
    (elixir 1.10.3) expanding macro: Kernel.@/1
    lib/Sandbox.ex:4: Sandbox (module)

What’s the correct way to TypeCheck the multiple function arguments in foo/3?

1 Like