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