Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule to test for uninitialized pointers in derived types #299

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

imciner2
Copy link
Contributor

@imciner2 imciner2 commented Jan 15, 2025

Unlike normal variables in procedures, derived types can have non-saved default initializer values, and it is safest to ensure that pointers are associated, so that they can then be tested using intrinsics.

This is just the first type of variable to check in the derived types. Further checks can suggest default initializers on intrinsic typed variables.

Derived types can have non-saved default initializer values, and it is
safest to ensure that pointers are associated, so that they can then be
tested using intrinsics.
.map(|node| {
let var_name = node.to_text(src.source_text()).unwrap_or("").to_string();

let init_var = format!("{var_name} => null()");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates the variable name, see snapshot below:

20    |-        integer, pointer :: pI1, pI2
   20 |+        integer, pointer :: pI1pI1 => null(), pI2
Suggested change
let init_var = format!("{var_name} => null()");
let init_var = format!(" => null()");

#[derive_message_formats]
fn message(&self) -> String {
let Self { var } = self;
format!("'{var}' does not have a default initialiser")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something more explicit:

Suggested change
format!("'{var}' does not have a default initialiser")
format!("pointer component '{var}' does not have a default initialiser")

or is this too long-winded?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants