Skip to content

Commit

Permalink
fix: fixing some panic scenarios dues to invalid matching
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedroh committed Aug 23, 2024
1 parent 075824c commit 2d2c7e5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 15 deletions.
2 changes: 2 additions & 0 deletions bin/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ pub fn run_tool_on_merge_scenario(
right: &str,
) -> Result<ExecutionResult, ExecutionError> {
if base == left {
log::info!("Early returning because base equals left");
return Ok(ExecutionResult::WithoutConflicts(right.to_string()));
}

if base == right {
log::info!("Early returning because base equals right");
return Ok(ExecutionResult::WithoutConflicts(left.to_string()));
}

Expand Down
14 changes: 4 additions & 10 deletions bin/tests/scenarios/unordered_with_non_labelled/merge.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
public class Main { static { int
public class Main { static { int
<<<<<<<
x
x = 0
=======
y
y = 2
>>>>>>>
=
<<<<<<<
0
=======
2
>>>>>>>
; } static { System . out . println ( "I'm a static block" ) ; } public Main ( ) { System . out . println ( "I'm a constructor" ) ; int y = 3 ; } static { System . out . println ( "I don't know what's going on" ) ; } }
; } static { System . out . println ( "I'm a static block" ) ; } public Main ( ) { System . out . println ( "I'm a constructor" ) ; int y = 3 ; } static { System . out . println ( "I don't know what's going on" ) ; } }
59 changes: 54 additions & 5 deletions merge/src/ordered_merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ pub fn ordered_merge<'a>(
right_matching_in_left,
matching_base_right,
) {
(true, Some(_), Some(_), Some(_), Some(_)) => {
(true, Some(_), Some(matching_base_left), Some(_), Some(_)) => {
result_children.push(crate::merge(
cur_left,
matching_base_left.matching_node,
cur_left,
cur_right,
base_left_matchings,
Expand All @@ -68,6 +68,32 @@ pub fn ordered_merge<'a>(
cur_left_option = children_left_it.next();
cur_right_option = children_right_it.next();
}
(true, Some(_), Some(matching_base_left), Some(_), None) => {
result_children.push(crate::merge(
matching_base_left.matching_node,
cur_left,
cur_right,
base_left_matchings,
base_right_matchings,
left_right_matchings,
)?);

cur_left_option = children_left_it.next();
cur_right_option = children_right_it.next();
}
(true, Some(_), None, Some(_), Some(matching_base_right)) => {
result_children.push(crate::merge(
matching_base_right.matching_node,
cur_left,
cur_right,
base_left_matchings,
base_right_matchings,
left_right_matchings,
)?);

cur_left_option = children_left_it.next();
cur_right_option = children_right_it.next();
}
(false, Some(_), Some(_), None, Some(matching_base_right)) => {
if !matching_base_right.is_perfect_match {
result_children.push(MergedCSTNode::Conflict {
Expand Down Expand Up @@ -182,13 +208,36 @@ pub fn ordered_merge<'a>(
cur_right_option = children_right_it.next();
}
(a, b, c, d, e) => {
return Err(MergeError::InvalidMatchingConfiguration(
log::warn!(
"Reached an Invalid Matching Configuration. {} {} {} {} {}",
a,
b.is_some(),
c.is_some(),
d.is_some(),
e.is_some(),
));
e.is_some()
);
log::debug!(
"Involved nodes {} AND {}",
cur_left.contents(),
cur_right.contents()
);
log::debug!(
"Involved nodes parents {} AND {}",
left.contents(),
right.contents()
);

if cur_left.contents() == cur_right.contents() {
result_children.push(cur_left.into())
} else {
result_children.push(MergedCSTNode::Conflict {
left: Some(Box::new(cur_left.into())),
right: Some(Box::new(cur_right.into())),
})
}

cur_left_option = children_left_it.next();
cur_right_option = children_right_it.next();
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions parsing/src/tree_sitter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ impl From<Language> for ParserConfiguration {
tree_sitter_java::language(),
)),
);

map.insert(
"variable_declarator",
Box::new(TreeSitterQuery::new(
r#"(variable_declarator (identifier) @name)"#,
tree_sitter_java::language(),
)),
);
map
},
},
Expand Down

0 comments on commit 2d2c7e5

Please sign in to comment.