From c3eeb8624baa639e049d113e111a6a4358d6799c Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Wed, 7 Mar 2018 17:46:16 +0300 Subject: [PATCH] Strip duplicates from module's options --- src/gen_mod.erl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gen_mod.erl b/src/gen_mod.erl index a477ec295..836e9dba8 100644 --- a/src/gen_mod.erl +++ b/src/gen_mod.erl @@ -555,7 +555,8 @@ validate_opts(Host, Module, Opts0) -> undef -> Opts; Validators -> - validate_opts(Host, Module, Opts, Required, Validators) + Opts1 = validate_opts(Host, Module, Opts, Required, Validators), + remove_duplicated_opts(Opts1) end} catch _:{missing_required_option, Opt} -> ErrTxt = io_lib:format("Module '~s' is missing required option '~s'", @@ -680,6 +681,16 @@ merge_opts(Opts, DefaultOpts) -> end end, Result, Opts). +remove_duplicated_opts([{Opt, Val}, {Opt, _Default}|Opts]) -> + [{Opt, Val}|remove_duplicated_opts(Opts)]; +remove_duplicated_opts([{Opt, [{SubOpt, _}|_] = SubOpts}|Opts]) + when is_atom(SubOpt) -> + [{Opt, remove_duplicated_opts(SubOpts)}|remove_duplicated_opts(Opts)]; +remove_duplicated_opts([OptVal|Opts]) -> + [OptVal|remove_duplicated_opts(Opts)]; +remove_duplicated_opts([]) -> + []. + -spec get_submodules(binary(), module(), opts()) -> [module()]. get_submodules(Host, Module, Opts) -> try Module:mod_options(Host) of -- 2.40.0