Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

Fix echo tuple format

+61 -5
+3
CHANGELOG.md
··· 12 12 13 13 ### Bug fixes 14 14 15 + - Fixed a bug where tuples with atoms in the first position could be 16 + incorrectly formatted by `echo`. 17 + 15 18 ## v1.9.1 - 2025-03-10 16 19 17 20 ### Formatter
+15 -5
compiler-core/templates/echo.erl
··· 88 88 inspect@map(Map) -> 89 89 Fields = [ 90 90 [<<"#(">>, echo@inspect(Key), <<", ">>, echo@inspect(Value), <<")">>] 91 - || {Key, Value} <- maps:to_list(Map) 91 + || {Key, Value} <- maps:to_list(Map) 92 92 ], 93 93 ["dict.from_list([", lists:join(", ", Fields), "])"]. 94 94 95 95 inspect@record(Record) -> 96 - [Atom | ArgsList] = erlang:tuple_to_list(Record), 97 - Args = lists:join(", ", lists:map(fun echo@inspect/1, ArgsList)), 98 - [echo@inspect(Atom), "(", Args, ")"]. 96 + [Atom | ArgsList] = Tuple = erlang:tuple_to_list(Record), 97 + case inspect@maybe_gleam_atom(Atom, none, <<>>) of 98 + {ok, Tag} -> 99 + Args = lists:join(", ", lists:map(fun echo@inspect/1, ArgsList)), 100 + [Tag, "(", Args, ")"]; 101 + _ -> 102 + inspect@tuple(Tuple) 103 + end. 99 104 105 + inspect@tuple(Tuple) when erlang:is_tuple(Tuple) -> 106 + inspect@tuple(erlang:tuple_to_list(Tuple)); 100 107 inspect@tuple(Tuple) -> 101 - Elements = lists:map(fun echo@inspect/1, erlang:tuple_to_list(Tuple)), 108 + Elements = lists:map(fun echo@inspect/1, Tuple), 102 109 ["#(", lists:join(", ", Elements), ")"]. 103 110 104 111 inspect@function(Function) -> ··· 147 154 {improper, [echo@inspect(First), " | ", echo@inspect(ImproperRest)]} 148 155 end. 149 156 157 + inspect@maybe_gleam_atom(Atom, PrevChar, Acc) when erlang:is_atom(Atom) -> 158 + Binary = erlang:atom_to_binary(Atom), 159 + inspect@maybe_gleam_atom(Binary, PrevChar, Acc); 150 160 inspect@maybe_gleam_atom(Atom, PrevChar, Acc) -> 151 161 case {Atom, PrevChar} of 152 162 {<<>>, none} ->
+2
test-output/cases/echo_non_record_atom_tag/gleam.toml
··· 1 + name = "echo_non_record_atom_tag" 2 + version = "1.0.0"
+10
test-output/cases/echo_non_record_atom_tag/src/main.gleam
··· 1 + pub fn main() { 2 + echo #(to_atom("UP"), 1, 2) 3 + echo #(to_atom("down"), 12.34) 4 + echo #(to_atom("Both"), "ok") 5 + } 6 + 7 + pub type Atom 8 + 9 + @external(erlang, "erlang", "binary_to_atom") 10 + pub fn to_atom(string: String) -> Atom
+5
test-output/src/tests/echo.rs
··· 185 185 fn echo_tuple() { 186 186 assert_echo!("echo_tuple"); 187 187 } 188 + 189 + #[test] 190 + fn echo_non_record_atom_tag() { 191 + assert_echo!(Target::Erlang, "echo_non_record_atom_tag"); 192 + }
+26
test-output/src/tests/snapshots/test_output__tests__echo__erlang-echo_non_record_atom_tag.snap
··· 1 + --- 2 + source: test-output/src/tests/echo.rs 3 + assertion_line: 191 4 + expression: output 5 + snapshot_kind: text 6 + --- 7 + --- main.gleam ---------------------- 8 + pub fn main() { 9 + echo #(to_atom("UP"), 1, 2) 10 + echo #(to_atom("down"), 12.34) 11 + echo #(to_atom("Both"), "ok") 12 + } 13 + 14 + pub type Atom 15 + 16 + @external(erlang, "erlang", "binary_to_atom") 17 + pub fn to_atom(string: String) -> Atom 18 + 19 + 20 + --- gleam run output ---------------- 21 + src/main.gleam:2 22 + #(atom.create_from_string("UP"), 1, 2) 23 + src/main.gleam:3 24 + Down(12.34) 25 + src/main.gleam:4 26 + #(atom.create_from_string("Both"), "ok")