Skip to content

Commit 896fe85

Browse files
committed
fix(to_cpp1): lower _braced-init-list_ argument
1 parent 7fff368 commit 896fe85

6 files changed

+120
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
point: @value type = {
2+
public x: int = 0;
3+
public y: int = 0;
4+
operator=: (implicit out this, x_: int, y_: int) = {
5+
x = x_;
6+
y = y_;
7+
}
8+
}
9+
10+
check: (p: point) p;
11+
12+
main: () = {
13+
assert(check((17, 29)).x == 17);
14+
assert(check((17, 29)).y == 29);
15+
16+
//board: std::array<std::array<u8, 3>, 3> = ((
17+
// ('O', 'X', 'O'),
18+
// (' ', 'X', 'X'),
19+
// ('X', 'O', 'O')
20+
//));
21+
//assert(board[0] == :std::array<u8, 3> = ('O', 'X', 'O'));
22+
//assert(board[1] == :std::array<u8, 3> = (' ', 'X', 'X'));
23+
//assert(board[2] == :std::array<u8, 3> = ('X', 'O', 'O'));
24+
25+
// Still parentheses
26+
assert((:std::vector = (17, 29)).size() == 2);
27+
}

regression-tests/test-results/gcc-13/pure2-bugfix-for-nested-lists.cpp.execution

Whitespace-only changes.

regression-tests/test-results/gcc-13/pure2-bugfix-for-nested-lists.cpp.output

Whitespace-only changes.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
2+
#define CPP2_IMPORT_STD Yes
3+
4+
//=== Cpp2 type declarations ====================================================
5+
6+
7+
#include "cpp2util.h"
8+
9+
#line 1 "pure2-bugfix-for-nested-lists.cpp2"
10+
class point;
11+
#line 2 "pure2-bugfix-for-nested-lists.cpp2"
12+
13+
14+
//=== Cpp2 type definitions and function declarations ===========================
15+
16+
#line 1 "pure2-bugfix-for-nested-lists.cpp2"
17+
class point {
18+
#line 2 "pure2-bugfix-for-nested-lists.cpp2"
19+
public: int x {0};
20+
public: int y {0};
21+
public: point(cpp2::in<int> x_, cpp2::in<int> y_);
22+
public: [[nodiscard]] auto operator<=>(point const& that) const& -> std::strong_ordering = default;
23+
public: point(point const& that);
24+
25+
public: auto operator=(point const& that) -> point& ;
26+
public: point(point&& that) noexcept;
27+
public: auto operator=(point&& that) noexcept -> point& ;
28+
public: explicit point();
29+
30+
#line 8 "pure2-bugfix-for-nested-lists.cpp2"
31+
};
32+
33+
[[nodiscard]] auto check(cpp2::in<point> p) -> auto;
34+
35+
auto main() -> int;
36+
37+
//=== Cpp2 function definitions =================================================
38+
39+
#line 1 "pure2-bugfix-for-nested-lists.cpp2"
40+
41+
#line 4 "pure2-bugfix-for-nested-lists.cpp2"
42+
point::point(cpp2::in<int> x_, cpp2::in<int> y_)
43+
: x{ x_ }
44+
, y{ y_ }{
45+
46+
#line 7 "pure2-bugfix-for-nested-lists.cpp2"
47+
}
48+
49+
50+
point::point(point const& that)
51+
: x{ that.x }
52+
, y{ that.y }{}
53+
54+
auto point::operator=(point const& that) -> point& {
55+
x = that.x;
56+
y = that.y;
57+
return *this;}
58+
point::point(point&& that) noexcept
59+
: x{ std::move(that).x }
60+
, y{ std::move(that).y }{}
61+
auto point::operator=(point&& that) noexcept -> point& {
62+
x = std::move(that).x;
63+
y = std::move(that).y;
64+
return *this;}
65+
point::point(){}
66+
#line 10 "pure2-bugfix-for-nested-lists.cpp2"
67+
[[nodiscard]] auto check(cpp2::in<point> p) -> auto { return p; }
68+
69+
auto main() -> int{
70+
if (cpp2::Default.has_handler() && !(check({17, 29}).x == 17) ) { cpp2::Default.report_violation(""); }
71+
if (cpp2::Default.has_handler() && !(check({17, 29}).y == 29) ) { cpp2::Default.report_violation(""); }
72+
73+
//board: std::array<std::array<u8, 3>, 3> = ((
74+
// ('O', 'X', 'O'),
75+
// (' ', 'X', 'X'),
76+
// ('X', 'O', 'O')
77+
//));
78+
//assert(board[0] == :std::array<u8, 3> = ('O', 'X', 'O'));
79+
//assert(board[1] == :std::array<u8, 3> = (' ', 'X', 'X'));
80+
//assert(board[2] == :std::array<u8, 3> = ('X', 'O', 'O'));
81+
82+
// Still parentheses
83+
if (cpp2::Default.has_handler() && !(CPP2_UFCS(size)((std::vector{17, 29})) == 2) ) { cpp2::Default.report_violation(""); }
84+
}
85+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pure2-bugfix-for-nested-lists.cpp2... ok (all Cpp2, passes safety checks)
2+

source/to_cpp1.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,6 +3132,12 @@ class cppfront
31323132
if (args) {
31333133
suffix.emplace_back(")", args.value().close_pos);
31343134
for (auto&& e: args.value().text_chunks) {
3135+
if (e.text == "(") {
3136+
e.text = "{";
3137+
}
3138+
else if (e.text == ")") {
3139+
e.text = "}";
3140+
}
31353141
suffix.push_back(e);
31363142
}
31373143
suffix.emplace_back("(", args.value().open_pos);

0 commit comments

Comments
 (0)