elixir-cldr / cldr

Elixir implementation of CLDR/ICU
Other
447 stars 33 forks source link

backend redefine warnings #130

Closed ayrat555 closed 5 years ago

ayrat555 commented 5 years ago

I compile my app with compile --warnings-as-errors

If I use any of the backends, for example ex_cldr_units. I'm getting

warning: redefining module BlockScoutWeb.Cldr.Number (current version loaded from /home/ayrat/Development/rockn/blockscout/_build/dev/lib/block_scout_web/ebin/Elixir.BlockScoutWeb.Cldr.Number.beam)
  lib/block_scout_web/cldr.ex:

which fails compilation

kipcole9 commented 5 years ago

Thanks for the report. Can you let me know:

  1. The version of ex_cldr and of the dependent packages you are using?
  2. An example backend configuration module that reports the error?
  3. The warning is always on *.Cldr.Number ?

That way I can build a simple test case to see how the issue arises.

ayrat555 commented 5 years ago
  1. {:ex_cldr, "~> 2.0"} -> 2.7.0
  2. dependent package is {:ex_cldr_units, "~> 2.5"} configuration module
    defmodule BlockScoutWeb.Cldr do
    use Cldr,
    default_locale: "en",
    locales: ["en"],
    gettext: BlockScoutWeb.Gettext,
    generate_docs: false
    end
  3. yes
kipcole9 commented 5 years ago

Thanks much, I'll work on this over the next 12 hours. Sorry for the inconvenience.

kipcole9 commented 5 years ago

May I also suggest update to ex_cldr version 2.7.2 which fixes an issue related to Gettext configuration in ex_cldr backend modules.

ayrat555 commented 5 years ago

I tried it with no success

kipcole9 commented 5 years ago

Hmmm, I'm not seeing the same symptoms as you. I have created the simplest repo I can at https://github.com/elixir-cldr/cldr_issue_130

If you have an opportunity, could you clone it and compile and see if you are getting the same warning result? I hard coded the current releases to be deterministic. I also added:

use Cldr,
  ...
  providers: [Cldr.Number, Cldr.Unit]

Although removing it has no noticeable difference other than silencing some console logging at compiler time.

ayrat555 commented 5 years ago

cldr_issue_130 is compiling without any warnings. I tried setting exactly the same deps versions but again the warning appears. Also, I tried to configure the library with otp_app option. no success.

Maybe the issue is related to umbrella applications?

kipcole9 commented 5 years ago

Any possibility you can give me access to your repo? I appreciate the answer may be "no" for confidentiality reasons, but it would certainly make it easier for me to work on the issue. I can't think of why an umbrella app would make a difference.

ayrat555 commented 5 years ago

no problem. it's here https://github.com/poanetwork/blockscout/pull/2473

kipcole9 commented 5 years ago

I believe the issue is that you are defining your own BlockScoutWeb.Cldr.Number module in block_scout_web/views/cldr/number.ex. This clashes with the generated module that comes from

defmodule BlockScoutWeb.Cldr do
  use Cldr,
    default_locale: "en",
    locales: ["en"],
    gettext: BlockScoutWeb.Gettext,
    generate_docs: false,
    providers: [Cldr.Number, Cldr.Unit]
end

You note that you see a bug in Cldr.Number.to_string!/3. Let me know what the wrong behaviour is and I'll work on fixing that. A failing example would be a big help.

In general it is best to not create modules under the namespace of the Cldr backend module. That is, don't create any module that starts with BlockScoutWeb.Cldr in this case. I will update the documentation to make a note of that.

kipcole9 commented 5 years ago

I also recommend changing

config :ex_cldr,
  default_locale: "en",
  locales: ["en"],
  gettext: BlockScoutWeb.Gettext

to

config :ex_cldr,
  default_locale: "en"

in apps/config/config.exs

kipcole9 commented 5 years ago

Oh, I see that your private BlockScoutWeb.Cldr.Niumber module was working around some old dialyzer errors. ex_cldr and friends now all pass dialyzer so I wouldn't expect you to need this module any more.

ayrat555 commented 5 years ago

@kipcole9 thanks. the issue was in the conflicting module name. renaming it fixed the issue