diff --git a/src/hocon_tconf.erl b/src/hocon_tconf.erl index 4965b7c..7d468d7 100644 --- a/src/hocon_tconf.erl +++ b/src/hocon_tconf.erl @@ -561,9 +561,16 @@ map_field(?MAP(NameType, Type), FieldSchema, Value, Opts) -> case check_map_key_name(NameType, FieldNames) of ok -> %% All objects in this map should share the same schema. + %% And each fake 'field' should not have any alias + %% because the alias belongs to the parent field NewSc = hocon_schema:override( FieldSchema, - #{type => Type, mapping => undefined, converter => undefined} + #{ + type => Type, + mapping => undefined, + converter => undefined, + aliases => [] + } ), NewFields = [{FieldName, NewSc} || FieldName <- FieldNames], %% start over diff --git a/test/hocon_tconf_tests.erl b/test/hocon_tconf_tests.erl index 24dda89..ba5483e 100644 --- a/test/hocon_tconf_tests.erl +++ b/test/hocon_tconf_tests.erl @@ -2571,3 +2571,18 @@ random_key() -> Bytes = crypto:strong_rand_bytes(10), Key0 = base64:encode(Bytes), iolist_to_binary(re:replace(Key0, <<"[^-a-zA-Z0-9_]">>, <<>>, [global])). + +map_type_with_alias_test() -> + Sc = #{ + roots => [ + {"root", hoconsc:mk(hoconsc:map(name, hoconsc:ref(foo)), #{aliases => [foo]})} + ], + fields => + #{foo => [{bar, hoconsc:mk(integer(), #{})}]} + }, + MapValue = #{<<"foo">> => #{<<"bar">> => 0}}, + NormalRecord = #{<<"root">> => MapValue}, + AliasedRecord = #{<<"foo">> => MapValue}, + ?assertEqual(NormalRecord, hocon_tconf:check_plain(Sc, NormalRecord)), + ?assertEqual(NormalRecord, hocon_tconf:check_plain(Sc, AliasedRecord)), + ok.