Skip to content

Commit

Permalink
validation: Add temporary(?) validation
Browse files Browse the repository at this point in the history
  • Loading branch information
volsa committed Jan 30, 2025
1 parent 1feafe2 commit 4c1aadc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/plc_driver/src/pipelines/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl PipelineParticipantMut for PropertyLowerer {
self.annotations = Some(annotations);

for AnnotatedUnit { unit, .. } in &mut units.iter_mut() {
self.lower_identifiers_to_calls(unit);
self.lower_references_to_calls(unit);
}

let project = AnnotatedProject { units, index, annotations: self.annotations.take().unwrap() };
Expand Down
8 changes: 5 additions & 3 deletions src/lowering/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ impl PropertyLowerer {
PropertyLowerer { id_provider, annotations: None, context: None }
}
}

impl PropertyLowerer {
pub fn lower_identifiers_to_calls(&mut self, unit: &mut CompilationUnit) {
pub fn lower_references_to_calls(&mut self, unit: &mut CompilationUnit) {
self.visit_compilation_unit(unit);
}
}
Expand Down Expand Up @@ -82,6 +83,7 @@ impl AstVisitorMut for PropertyLowerer {

let _ = std::mem::replace(node, call);
}

_ => (),
}
}
Expand Down Expand Up @@ -341,7 +343,7 @@ mod tests {

// Lower
lowerer.annotations = Some(annotations);
lowerer.lower_identifiers_to_calls(&mut unit);
lowerer.lower_references_to_calls(&mut unit);

insta::assert_debug_snapshot!(unit.implementations, @r#"
[
Expand Down Expand Up @@ -710,7 +712,7 @@ mod tests {

// Lower
lowerer.annotations = Some(annotations);
lowerer.lower_identifiers_to_calls(&mut unit);
lowerer.lower_references_to_calls(&mut unit);

insta::assert_debug_snapshot!(unit.implementations, @r#"
[
Expand Down
26 changes: 26 additions & 0 deletions src/validation/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,32 @@ fn validate_reference<T: AnnotationMap>(
) {
// unresolved reference
if !context.annotations.has_type_annotation(statement) {
// XXX: Temporary solution, is there a better way? Technically we could introduce a diagnostic when
// lowering the references to calls, then checking with the index if the defined POU exists but
// then we'd get two similar error, one describing what the exact issue is (i.e. no get/set) and
// the other describing that it cant find a reference to "__{get,set}_<property name>"
match ref_name {
_ if ref_name.starts_with("__set") => {
validator.push_diagnostic(
Diagnostic::new("SET property not defined")
.with_error_code("E048")
.with_location(location),
);
return;
}

_ if ref_name.starts_with("__get") => {
validator.push_diagnostic(
Diagnostic::new("GET property not defined")
.with_error_code("E048")
.with_location(location),
);
return;
}

_ => (),
};

validator.push_diagnostic(Diagnostic::unresolved_reference(ref_name, location));

// was this meant as a direct access?
Expand Down

0 comments on commit 4c1aadc

Please sign in to comment.