esl / gradient

Gradient is a static typechecker for Elixir
Apache License 2.0
435 stars 13 forks source link

Gradient doesn't understand `nonempty_improper_list` #181

Open mariari opened 5 months ago

mariari commented 5 months ago

Here is a reproducible example

  @type failed() :: nonempty_improper_list(number(), number())

  @spec foo() :: failed()
  def foo() do
    [2, 1 | 0]
  end

Ends up with the message

lib/nock.ex: The pattern [id, key | zero] on line 1249 doesn't have the type noun_atom() | noun_cell()

lib/nock.ex: The list on line 1277 is expected to have type failed() but it has type nonempty_list()
1275   @spec foo() :: failed()
1276   def foo() do
1277     [2, 1 | 0]
1278   end
1279 end

To get this to work, I have to replace this with this

  @type failed() :: list(number) | number()

As it resolves [...] as solely a list, and then number as the termination matching