elixir-cldr / cldr_numbers

CLDR Number localisation and formatting
Other
41 stars 23 forks source link

Cannot match because a previous clause always matches #24

Closed koszta closed 2 years ago

koszta commented 2 years ago

I've noticed the following warnings when compiling a project with cldr_numbers:

warning: this clause for decimal_format_list_for/1 cannot match because a previous clause at line 1 always matches
  lib/cldr/number/backend/format.ex:1

warning: this clause for number_system_from_locale/1 cannot match because a previous clause at line 1 always matches
  lib/cldr/number/backend/system.ex:1

warning: this clause for number_symbols_for/1 cannot match because a previous clause at line 1 always matches
  lib/cldr/number/backend/symbol.ex:1

As it seems like these are related to the changes to make dialyzer pass.

https://github.com/elixir-cldr/cldr_numbers/commit/1338313fa070ba00f472169200c2883b633ea874

def number_system_from_locale(locale) do
  Cldr.Number.System.number_system_from_locale(locale, unquote(backend))
end

def number_system_from_locale(%LanguageTag{} = locale) do
  Cldr.Number.System.number_system_from_locale(locale, unquote(backend))
end

To prevent these we are running mix compile --warnings-as-errors on the CI.

kipcole9 commented 2 years ago

Thanks for the report, much appreciated. I'm not seeing this on my side so I wonder if you can share your backend module configuration? That should help me trigger the same issue and then work out why this is happening.

koszta commented 2 years ago

Sure, that's all I have:

config/config.exs

# ...

config :ex_cldr,
  default_locale: "en",
  json_library: Poison,
  default_backend: ApiWeb.Cldr

config :api, ApiWeb.Cldr,
  providers: [Cldr.Number, Cldr.Calendar, Cldr.DateTime],
  gettext: ApiWeb.Gettext,
  default_locale: "en",
  locales: ~w(
    cs
    da
    de-AT
    de-CH
    de
    en-AU
    en-CA
    en-GB
    en-IE
    en-IN
    en-NZ
    en
    es-AR
    es-CL
    es-CO
    es
    es-MX
    es-PE
    fi
    fr-BE
    fr-CH
    fr
    fr-LU
    hu
    it-CH
    it
    ja
    nb
    nl-BE
    nl
    pl
    pt-PT
    pt
    ru
    sv
    tr
    zh-Hans
    zh-Hans-HK
  )

# ...

lib/api_web/cldr.ex

defmodule ApiWeb.Cldr do
  use Cldr, otp_app: :api
end

It is possible that some of the files weren't re-compiled and therefore the warnings don't appear. Maybe mix compile --force --warnings-as-errors would help or removing _build and then compiling the project.

kipcole9 commented 2 years ago

Very curious. I created a test app with the configuration you outlined above and I not seeing the warnings. Perhaps you could clone the test app on your system and see if you get the compilation warnings?

Here is the mix.lock I am using in case we have different versions in play:

%{
  "cldr_utils": {:hex, :cldr_utils, "2.17.1", "d5532ccfbe4b39cb652ba4566571324278344a6a2fb4500dac213ce8e123732f", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "052e0c2cf5ee801018580d69939b25528730d73ea05a05cb2c0e0a8204856d76"},
  "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
  "ex_cldr": {:hex, :ex_cldr, "2.26.1", "417d6a8928ff854df01a8830aab2c9a4d8963db922d35180dcab5adf76dfaf62", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:cldr_utils, "~> 2.17", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.19", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "b666dd854562a8c27cff7d434ecc2c0c06c2a23fd1dfd3a1b5b554b9f9d1e455"},
  "ex_cldr_calendars": {:hex, :ex_cldr_calendars, "1.18.0", "aa86e673f02b3c65d9cc29c483a4dfec1878b2e2460619c2b06c121ef801334e", [:mix], [{:calendar_interval, "~> 0.2", [hex: :calendar_interval, repo: "hexpm", optional: true]}, {:ex_cldr_lists, "~> 2.10", [hex: :ex_cldr_lists, repo: "hexpm", optional: true]}, {:ex_cldr_numbers, "~> 2.25", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:ex_cldr_units, "~> 3.12", [hex: :ex_cldr_units, repo: "hexpm", optional: true]}, {:ex_doc, "~> 0.21", [hex: :ex_doc, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "5b47bf4e90bdd6746ac9ca9cb3f9d36c3e656c18768ace8366061e3e02899cdc"},
  "ex_cldr_currencies": {:hex, :ex_cldr_currencies, "2.13.0", "13188b99e527d724ed3dc2af37e54f0dac42dec42b620a34c4ed4d4902fad6dd", [:mix], [{:ex_cldr, "~> 2.24", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "64731e49ac3530aa88872b52c319eb5231bfb1a3ebb0956044c34abc0ed4f520"},
  "ex_cldr_dates_times": {:hex, :ex_cldr_dates_times, "2.11.0", "eb00d2def8c16feb250ea2436c2e07b31b6e0ad22f9ff569c7714e807c8327df", [:mix], [{:calendar_interval, "~> 0.2", [hex: :calendar_interval, repo: "hexpm", optional: true]}, {:ex_cldr_calendars, "~> 1.18", [hex: :ex_cldr_calendars, repo: "hexpm", optional: false]}, {:ex_cldr_numbers, "~> 2.25", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "36b2dd6bea88f295b9761d6ca26cccce573708cffe6e196f9930a24ca57baecf"},
  "ex_cldr_numbers": {:hex, :ex_cldr_numbers, "2.25.0", "2907ea158b16df80b191da541c20b296be19603d403b06d6cc391040406a73a6", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:ex_cldr, "~> 2.26", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_currencies, "~> 2.13", [hex: :ex_cldr_currencies, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "0ffe66487bb202d149c2183af1374bd98f1d0a7278a91cbfe120f0eb0555a952"},
  "jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
  "poison": {:hex, :poison, "5.0.0", "d2b54589ab4157bbb82ec2050757779bfed724463a544b6e20d79855a9e43b24", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "11dc6117c501b80c62a7594f941d043982a1bd05a1184280c0d9166eb4d8d3fc"},
}
kipcole9 commented 2 years ago

Ah, interesting. No warnings on Elixir 1.13, but the warnings do arrive on Elixir 1.11. That gives me something to work on - will revert ASAP. In my CI I do delete the _build directory and I run tests and dialyzer on Elixir 1.10 to Elixir 1.13 but I haven't enabled --warnings-as-errors so thats a good prompt, thanks.

kipcole9 commented 2 years ago

I have published ex_cldr_numbers version 2.25.1 that fixes this issue. The changelog entry reads:

Bug Fixes

Thanks much for the report and collaboration, let me know if you see any other issues.