fix: Restrict commutativity of initializer_list in C/C++ #377

Merged
wetneb merged 1 commit from wetneb/mergiraf:262-cpp-initializer_list into main 2025-05-10 19:26:35 +02:00

View file

@ -0,0 +1,5 @@
json func() {
return json{{"num", 0},
{"obj", {{"a", 1}, {"b", 2}}},
{"list", json::array({{{"a", 3}, {"b", 4}}})}};
}

View file

@ -0,0 +1,17 @@
json func() {
return json{{"num", 0},
<<<<<<< LEFT
{"list", json::array({{{"a", 1}, {"b", 2}}})},
||||||| BASE
{{"num", 0},
{"obj", {{"a", 1}, {"b", 2}}},
{"list", json::array({{{"a", 3}, {"b", 4}}})}},
=======
{{"num", 0},
{"obj", {{"a", 1}, {"b", 2}}},
{"list", json::array({{{"a", 3}, {"b", 4}}})},
{"c", 5}},
>>>>>>> RIGHT
{"other", {{"a", 3}, {"b", 4}}},
{"c", 5}};
}

View file

@ -0,0 +1,6 @@
json func() {
return json{{"num", 0},
{"list", json::array({{{"a", 1}, {"b", 2}}})},
{"other", {{"a", 3}, {"b", 4}}},
{"c", 5}};
}

View file

@ -0,0 +1 @@
Taken from https://codeberg.org/mergiraf/mergiraf/issues/262

View file

@ -0,0 +1,6 @@
json func() {
return json{{"num", 0},
{"obj", {{"a", 1}, {"b", 2}}},
{"list", json::array({{{"a", 3}, {"b", 4}}})},
{"c", 5}};
}

View file

@ -0,0 +1,3 @@
my_struct_t instance = {
"hello"
};

View file

@ -0,0 +1,11 @@
my_struct_t instance = {
<<<<<<< LEFT
"hello",
"merhaba",
||||||| BASE
"hello"
=======
"hello",
"salut",
>>>>>>> RIGHT
};

View file

@ -0,0 +1,4 @@
my_struct_t instance = {
"hello",
"merhaba",
};

View file

@ -0,0 +1,4 @@
my_struct_t instance = {
"hello",
"salut",
};

View file

@ -444,7 +444,8 @@ pub static SUPPORTED_LANGUAGES: LazyLock<Vec<LangProfile>> = LazyLock::new(|| {
language: tree_sitter_cpp::LANGUAGE.into(),
atomic_nodes: vec![],
commutative_parents: vec![
CommutativeParent::new("initializer_list", "{", ",", "}"),
CommutativeParent::new("initializer_list", "{", ",", "}")
.restricted_to_groups(&[&["initializer_pair"]]),
CommutativeParent::new("field_declaration_list", "{\n", "\n", "\n}\n")
.restricted_to_groups(&[&["field_declaration"], &["function_definition"]]),
],