Skip to content

Commit e1a8c8b

Browse files
authored
Merge branch 'master' into master
2 parents aa20938 + 4b5e8ff commit e1a8c8b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/validation/stmt_validator.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,11 @@ impl StatementValidator {
381381
if variable_type.is_private()
382382
&& context
383383
.qualifier
384-
.map_or(false, |q| !qualified_name.starts_with(q))
384+
.and_then(|it| context.index.find_pou(it)) //Get the container pou (for actions this is the program/fb)
385+
.map(|it| (it.get_name(), it.get_container()))
386+
.map_or(false, |(it, container)| {
387+
!qualified_name.starts_with(it) && !qualified_name.starts_with(container)
388+
})
385389
{
386390
self.diagnostics.push(Diagnostic::illegal_access(
387391
qualified_name.as_str(),

src/validation/tests/reference_resolve_tests.rs

+20
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,23 @@ fn reference_to_private_variable_in_intermediate_fb() {
298298
vec![Diagnostic::illegal_access("fb1.f", (413..414).into()),]
299299
);
300300
}
301+
302+
#[test]
303+
fn program_vars_are_allowed_in_their_actions() {
304+
let diagnostics = parse_and_validate(
305+
"
306+
PROGRAM prg
307+
VAR
308+
s : INT;
309+
END_VAR
310+
END_PROGRAM
311+
312+
ACTION prg.foo
313+
prg.s := 7;
314+
s := 7;
315+
END_ACTION
316+
",
317+
);
318+
319+
assert_eq!(diagnostics, vec![]);
320+
}

0 commit comments

Comments
 (0)