Skip to content

Commit bca86d2

Browse files
authored
fix: make sure actions called from other actions get resolved (#980)
1 parent d29c8d2 commit bca86d2

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

compiler/plc_driver/src/runner.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ pub fn compile<T: Compilable>(context: &CodegenContext, source: T) -> GeneratedM
3838
..Default::default()
3939
};
4040

41-
dbg!(&annotated_project.units[0].0);
4241
annotated_project.generate_single_module(context, &compile_options).unwrap().unwrap()
4342
}
4443

src/resolver.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,10 @@ impl ResolvingScope {
19801980
index.find_pou(name).and_then(|pou| to_pou_annotation(pou, index)).or_else(|| {
19811981
ctx.pou.and_then(|pou|
19821982
// retry with local pou as qualifier
1983-
ResolvingScope::POU.resolve_name(name, Some(pou), index, ctx))
1983+
//Use the type name of the pou in case we are resolving a
1984+
//neighboring action
1985+
index.find_pou(pou).map(|pou| pou.get_container())
1986+
.and_then(|pou|ResolvingScope::POU.resolve_name(name, Some(pou), index, ctx)))
19841987
})
19851988
}
19861989
}

src/resolver/tests/resolve_expressions_tests.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4279,6 +4279,48 @@ fn action_call_statement_parameters_are_annotated_with_a_type_hint() {
42794279
}
42804280
}
42814281

4282+
#[test]
4283+
fn action_called_from_other_action_resolved() {
4284+
let id_provider = IdProvider::default();
4285+
let (unit, mut index) = index_with_ids(
4286+
r#"
4287+
PROGRAM mainProg
4288+
VAR
4289+
END_VAR
4290+
act1();
4291+
END_PROGRAM
4292+
4293+
ACTIONS
4294+
ACTION act1
4295+
act2();
4296+
END_ACTION
4297+
ACTION act2
4298+
act1();
4299+
END_ACTION
4300+
END_ACTIONS
4301+
"#,
4302+
id_provider.clone(),
4303+
);
4304+
4305+
let annotations = annotate_with_ids(&unit, &mut index, id_provider);
4306+
4307+
//Actions are annotated corretly
4308+
let AstStatement::CallStatement(CallStatement { operator, .. }) = unit.implementations[0].statements[0].get_stmt() else {
4309+
unreachable!()
4310+
};
4311+
assert_eq!(annotations.get_call_name(operator).unwrap(), "mainProg.act1");
4312+
4313+
let AstStatement::CallStatement(CallStatement { operator, .. }) = unit.implementations[1].statements[0].get_stmt() else {
4314+
unreachable!()
4315+
};
4316+
assert_eq!(annotations.get_call_name(operator).unwrap(), "mainProg.act2");
4317+
4318+
let AstStatement::CallStatement(CallStatement { operator, .. }) = unit.implementations[2].statements[0].get_stmt() else {
4319+
unreachable!()
4320+
};
4321+
assert_eq!(annotations.get_call_name(operator).unwrap(), "mainProg.act1");
4322+
}
4323+
42824324
#[test]
42834325
fn vla_struct_reference_is_annotated_as_array() {
42844326
let id_provider = IdProvider::default();

src/test_utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ pub mod tests {
105105

106106
pub fn parse_and_validate_buffered(src: &str) -> String {
107107
let diagnostics = parse_and_validate(src);
108-
dbg!(&diagnostics);
109108
let mut reporter = Diagnostician::buffered();
110109

111110
reporter.register_file("<internal>".to_string(), src.to_string());

src/validation/tests/variable_length_array_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ mod program {
6464
#[test]
6565
fn variable_length_array_program_input_ref() {
6666
let program = SOURCE.replace("<POU_TYPE>", "PROGRAM");
67-
let program_input = parse_and_validate(dbg!(&program.replace("<VAR_TYPE>", "INPUT {ref}")));
67+
let program_input = parse_and_validate(&program.replace("<VAR_TYPE>", "INPUT {ref}"));
6868
assert_validation_snapshot!(program_input);
6969
}
7070

0 commit comments

Comments
 (0)