-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: lower (nested) _braced-init-list_ (argument) #927
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
point: @value type = { | ||
public x: int = 0; | ||
public y: int = 0; | ||
operator=: (implicit out this, x_: int, y_: int) = { | ||
x = x_; | ||
y = y_; | ||
} | ||
} | ||
|
||
check: (p: point) p; | ||
|
||
main: () = { | ||
assert(check((17, 29)).x == 17); | ||
assert(check((17, 29)).y == 29); | ||
|
||
board: std::array<std::array<u8, 3>, 3> = (( | ||
('O', 'X', 'O'), | ||
(' ', ('X'), 'X'), | ||
('X', 'O', 'O') | ||
)); | ||
assert(board[0] == :std::array<u8, 3> = ('O', 'X', 'O')); | ||
assert(board[1] == :std::array<u8, 3> = (' ', 'X', 'X')); | ||
assert(board[2] == :std::array<u8, 3> = ('X', 'O', 'O')); | ||
|
||
// Still parentheses (for now?) | ||
assert((:std::vector = (17, 29)).size() == 2); | ||
} | ||
|
||
issue_1283: () = { | ||
f := :() = { }; | ||
_ = :() = (f&$*)(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
|
||
#define CPP2_IMPORT_STD Yes | ||
|
||
//=== Cpp2 type declarations ==================================================== | ||
|
||
|
||
#include "cpp2util.h" | ||
|
||
#line 1 "pure2-bugfix-for-nested-lists.cpp2" | ||
class point; | ||
#line 2 "pure2-bugfix-for-nested-lists.cpp2" | ||
|
||
|
||
//=== Cpp2 type definitions and function declarations =========================== | ||
|
||
#line 1 "pure2-bugfix-for-nested-lists.cpp2" | ||
class point { | ||
#line 2 "pure2-bugfix-for-nested-lists.cpp2" | ||
public: int x {0}; | ||
public: int y {0}; | ||
public: point(cpp2::impl::in<int> x_, cpp2::impl::in<int> y_); | ||
public: [[nodiscard]] auto operator<=>(point const& that) const& -> std::strong_ordering = default; | ||
public: point(point const& that); | ||
|
||
public: auto operator=(point const& that) -> point& ; | ||
public: point(point&& that) noexcept; | ||
public: auto operator=(point&& that) noexcept -> point& ; | ||
public: explicit point(); | ||
|
||
#line 8 "pure2-bugfix-for-nested-lists.cpp2" | ||
}; | ||
|
||
[[nodiscard]] auto check(cpp2::impl::in<point> p) -> auto; | ||
|
||
auto main() -> int; | ||
|
||
#line 29 "pure2-bugfix-for-nested-lists.cpp2" | ||
auto issue_1283() -> void; | ||
|
||
//=== Cpp2 function definitions ================================================= | ||
|
||
#line 1 "pure2-bugfix-for-nested-lists.cpp2" | ||
|
||
#line 4 "pure2-bugfix-for-nested-lists.cpp2" | ||
point::point(cpp2::impl::in<int> x_, cpp2::impl::in<int> y_) | ||
: x{ x_ } | ||
, y{ y_ }{ | ||
|
||
#line 7 "pure2-bugfix-for-nested-lists.cpp2" | ||
} | ||
|
||
|
||
point::point(point const& that) | ||
: x{ that.x } | ||
, y{ that.y }{} | ||
|
||
auto point::operator=(point const& that) -> point& { | ||
x = that.x; | ||
y = that.y; | ||
return *this;} | ||
point::point(point&& that) noexcept | ||
: x{ std::move(that).x } | ||
, y{ std::move(that).y }{} | ||
auto point::operator=(point&& that) noexcept -> point& { | ||
x = std::move(that).x; | ||
y = std::move(that).y; | ||
return *this;} | ||
point::point(){} | ||
#line 10 "pure2-bugfix-for-nested-lists.cpp2" | ||
[[nodiscard]] auto check(cpp2::impl::in<point> p) -> auto { return p; } | ||
|
||
#line 12 "pure2-bugfix-for-nested-lists.cpp2" | ||
auto main() -> int{ | ||
if (cpp2::cpp2_default.is_active() && !(check({ 17, 29 }).x == 17) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(check({ 17, 29 }).y == 29) ) { cpp2::cpp2_default.report_violation(""); } | ||
|
||
std::array<std::array<cpp2::u8,3>,3> board {{ { | ||
'O', 'X', 'O' }, { | ||
' ', { 'X' }, 'X' }, { | ||
'X', 'O', 'O' } }}; | ||
|
||
if (cpp2::cpp2_default.is_active() && !(CPP2_ASSERT_IN_BOUNDS_LITERAL(board, 0) == std::array<cpp2::u8,3>{'O', 'X', 'O'}) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(CPP2_ASSERT_IN_BOUNDS_LITERAL(board, 1) == std::array<cpp2::u8,3>{' ', 'X', 'X'}) ) { cpp2::cpp2_default.report_violation(""); } | ||
if (cpp2::cpp2_default.is_active() && !(CPP2_ASSERT_IN_BOUNDS_LITERAL(cpp2::move(board), 2) == std::array<cpp2::u8,3>{'X', 'O', 'O'}) ) { cpp2::cpp2_default.report_violation(""); } | ||
|
||
// Still parentheses (for now?) | ||
if (cpp2::cpp2_default.is_active() && !(CPP2_UFCS(size)((std::vector{17, 29})) == 2) ) { cpp2::cpp2_default.report_violation(""); } | ||
} | ||
|
||
#line 29 "pure2-bugfix-for-nested-lists.cpp2" | ||
auto issue_1283() -> void{ | ||
auto f {[]() -> void{}}; | ||
static_cast<void>([_0 = (&f)]() mutable -> void { (*cpp2::impl::assert_not_null(_0))(); }); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pure2-bugfix-for-nested-lists.cpp2... ok (all Cpp2, passes safety checks) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ return ret; | |
|
||
mystruct::mystruct(auto&& i_, auto&& j_, auto&& k_) | ||
requires (std::is_convertible_v<CPP2_TYPEOF(i_), std::add_const_t<cpp2::i32>&> && std::is_convertible_v<CPP2_TYPEOF(j_), std::add_const_t<std::string>&> && std::is_convertible_v<CPP2_TYPEOF(k_), std::add_const_t<cpp2::u64>&>) | ||
: base{ (1) } | ||
: base{ 1 } | ||
This comment was marked as off-topic.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah, it must be a bug that I don't omit the braces when the context already implies some.
lowers to : std::vector<int>{ { 01 } } ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that |
||
, i{ CPP2_FORWARD(i_) } | ||
, j{ CPP2_FORWARD(j_) } | ||
, k{ CPP2_FORWARD(k_) }{} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, a semicolon doesn't work to delimit the unnamed declaration:
Also, I think
(0).f()
should lower toCPP2_UFCS(f)({0})
(despite #542 (comment)),just like
f((0))
lowers tof({0})
.This comment was marked as outdated.
Sorry, something went wrong.