Qqwy / elixir-type_check

TypeCheck: Fast and flexible runtime type-checking for your Elixir projects.
MIT License
516 stars 25 forks source link

`Date` and `DateTime` accept any map #74

Closed baldwindavid closed 2 years ago

baldwindavid commented 2 years ago

It seems that a spec with Date or DateTime accept anything that is a map. As an example, all of the below assertions work.

defmodule TypetestTest do
  use ExUnit.Case
  use TypeCheck

  defmodule User do
    defstruct []
  end

  @spec! run(Date.t()) :: true
  def run(_), do: true

  test "check types" do
    assert run(Date.utc_today())
    assert run(DateTime.utc_now())
    assert run(%User{})
    assert run(%{})

    assert_raise TypeCheck.TypeError, fn -> run("some string") end
    assert_raise TypeCheck.TypeError, fn -> run(6) end
    assert_raise TypeCheck.TypeError, fn -> run([]) end
  end
end
Qqwy commented 2 years ago

This was a regression introduced by the changes to allow function types. Luckily, finding the problem and fixing it was simple.

Thank you very much for reporting this issue! :heart_eyes:

Qqwy commented 2 years ago

(Verision 0.10.2 which includes the fix has been published)