From 54b22b142d17f0fd893ec2465e53b92109aadb48 Mon Sep 17 00:00:00 2001 From: Giacomo Cavalieri Date: Fri, 21 Apr 2023 15:04:50 +0200 Subject: Fix `dynamic.field` behaviour --- src/gleam_stdlib.erl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/gleam_stdlib.erl') diff --git a/src/gleam_stdlib.erl b/src/gleam_stdlib.erl index 33c9609..4c59893 100644 --- a/src/gleam_stdlib.erl +++ b/src/gleam_stdlib.erl @@ -78,12 +78,14 @@ decode_bool(Data) -> decode_error_msg(<<"Bool">>, Data). decode_list(Data) when is_list(Data) -> {ok, Data}; decode_list(Data) -> decode_error_msg(<<"List">>, Data). -decode_field(Data, Key) -> +decode_field(Data, Key) when is_map(Data) -> case Data of - #{Key := Value} -> {ok, Value}; + #{Key := Value} -> {ok, {ok, Value}}; _ -> - decode_error(<<"field"/utf8>>, <<"nothing"/utf8>>) - end. + {ok, decode_error(<<"field"/utf8>>, <<"nothing"/utf8>>)} + end; +decode_field(Data, _) -> + decode_error_msg(<<"Map">>, Data). size_of_tuple(Data) -> tuple_size(Data). -- cgit v1.2.3