Skip to content

Commit bb74795

Browse files
authored
fix: stackoverflow when parent name contains child-name separated by a _ (#1439)
1 parent f7ddafb commit bb74795

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ impl Index {
13931393
.and_then(|qualifier| self.find_member(qualifier, variable_name)))
13941394
// 'self' instance of a POUs init function
13951395
.or(container_name
1396-
.rfind('_')
1396+
.rfind("__init_")
13971397
.map(|p| &container_name[p + 1..])
13981398
.and_then(|qualifier| self.find_member(qualifier, variable_name)))
13991399
}

src/validation/tests/pou_validation_tests.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,34 @@ fn redeclaration_of_variables_from_super_super_is_an_error() {
450450
");
451451
}
452452

453+
#[test]
454+
fn underscore_separated_name_repetition_does_not_overflow_the_stack() {
455+
let diagnostics = parse_and_validate_buffered(
456+
"
457+
FUNCTION_BLOCK great_grandparent
458+
END_FUNCTION_BLOCK
459+
460+
FUNCTION_BLOCK grandparent EXTENDS great_grandparent
461+
VAR
462+
x : INT := 10;
463+
END_VAR
464+
END_FUNCTION_BLOCK
465+
466+
FUNCTION_BLOCK parent EXTENDS grandparent
467+
x := 100;
468+
END_FUNCTION_BLOCK
469+
",
470+
);
471+
472+
assert_snapshot!(diagnostics, @r"
473+
warning[E049]: Illegal access to private member grandparent.x
474+
┌─ <internal>:12:13
475+
476+
12 │ x := 100;
477+
│ ^ Illegal access to private member grandparent.x
478+
");
479+
}
480+
453481
#[test]
454482
fn signature_mismatch_between_base_and_interface() {
455483
let diagnostics = parse_and_validate_buffered(

0 commit comments

Comments
 (0)