elixir-sqlite / sqlitex

An Elixir wrapper around esqlite. Allows access to sqlite3 databases.
https://hex.pm/packages/sqlitex
120 stars 34 forks source link

Fix typespecs that refer to list of keywords but are instead coded as an empty list containing another empty list #92

Closed dimitarvp closed 4 years ago

dimitarvp commented 4 years ago

When doing something as simple as:

case Sqlitex.query!(conn, "pragma #{clause};") do
  [[{^key, value}]] ->
    single_value(key, value)

  values when is_list(values) ->
    multiple_values(key, values)
end

...I get this Dialyzer error:

lib/yourapp/yourapp.ex:100:pattern_match
The pattern can never match the type.

Pattern:
[[{_, _value}]]

Type:
[[]]

Upon inspecting Sqlitex's code, I noticed that the query / query! functions have two specs each (to cover for the default and non-default parameters) but where a list of zero or more keyword lists is expected to be returned, the spec says the function should return [[]].

This PR modifies the [[]] specs to the more accurate [keyword].

coveralls commented 4 years ago

Coverage Status

Coverage remained the same at 93.627% when pulling 0804760b589eab72d96273f90bccfc2f1136b2a4 on dimitarvp:fix-double-specs into 9c94469b862a43b7a36e31d1d295ff3d6f320491 on elixir-sqlite:master.