Skip to content

Commit

Permalink
fix(to_cpp1): lower indexed call in the correct order (#928)
Browse files Browse the repository at this point in the history
* test: add failing indexed call

* fix(to_cpp1): lower indexed call in the correct order
  • Loading branch information
JohelEGP authored Jan 11, 2024
1 parent 7fff368 commit c4e4dc9
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions regression-tests/pure2-bugfix-for-indexed-call.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
f: (_: i32) = { }
main: () = {
array_of_functions: std::array = (f, f);
index := 0;
arguments: i32 = 0;
array_of_functions[index](arguments);
_ = array_of_functions;
_ = index;
_ = arguments;
}
Empty file.
33 changes: 33 additions & 0 deletions regression-tests/test-results/pure2-bugfix-for-indexed-call.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

#define CPP2_IMPORT_STD Yes

//=== Cpp2 type declarations ====================================================


#include "cpp2util.h"

#line 1 "pure2-bugfix-for-indexed-call.cpp2"


//=== Cpp2 type definitions and function declarations ===========================

#line 1 "pure2-bugfix-for-indexed-call.cpp2"
auto f([[maybe_unused]] cpp2::in<cpp2::i32> unnamed_param_1) -> void;
#line 2 "pure2-bugfix-for-indexed-call.cpp2"
auto main() -> int;

//=== Cpp2 function definitions =================================================

#line 1 "pure2-bugfix-for-indexed-call.cpp2"
auto f([[maybe_unused]] cpp2::in<cpp2::i32> unnamed_param_1) -> void{}
#line 2 "pure2-bugfix-for-indexed-call.cpp2"
auto main() -> int{
std::array array_of_functions {f, f};
auto index {0};
cpp2::i32 arguments {0};
CPP2_ASSERT_IN_BOUNDS(array_of_functions, index)(arguments);
static_cast<void>(std::move(array_of_functions));
static_cast<void>(std::move(index));
static_cast<void>(std::move(arguments));
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pure2-bugfix-for-indexed-call.cpp2... ok (all Cpp2, passes safety checks)

2 changes: 2 additions & 0 deletions source/to_cpp1.h
Original file line number Diff line number Diff line change
Expand Up @@ -3322,6 +3322,8 @@ class cppfront
// Handle the suffix operators that remain suffix
//
else {
flush_args();

assert(i->op);
last_was_prefixed = false;

Expand Down

0 comments on commit c4e4dc9

Please sign in to comment.