WIP: Adding static class attribute definition functionality #312
No reviewers
Labels
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: M-Labs/nac3#312
Loading…
Reference in New Issue
No description provided.
Delete Branch "Aadityavardhan/nac3_sca:master"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Enabled class attribute definition syntax in the class body (Imp: Type checking/expression folding needs to be done).
Modified init checker to ensure that static fields do not need to be initialised in init.
@ -74,6 +74,7 @@ pub fn get_exn_constructor(
constructor: Some(signature),
resolver: None,
loc: None,
static_fields: Default::default(),
Is this the best place for this in this block of code?
@ -1040,6 +1040,7 @@ impl TopLevelComposer {
class_body_ast,
_class_ancestor_def,
class_fields_def,
class_static_fields_def, // Introduce static class attribute list into the function
What function?
Comment is incomprehensible.
@ -162,6 +162,7 @@ impl TopLevelComposer {
object_id: DefinitionId(index),
type_vars: Default::default(),
fields: Default::default(),
static_fields: Default::default(), // Initialize for constructor
Is this any different than the other lines in this block of code, which don't have a comment?
@ -93,2 +93,4 @@
fields: Vec<(StrRef, Type, bool)>,
// class methods, pointing to the corresponding function definition.
static_fields: Vec<(StrRef, Type, bool)>,
// list of static data members
Misplaced comment.
@ -1337,2 +1344,3 @@
}
ast::StmtKind::Assign { .. } => {}, // we don't class attributes
// Add assign branch since fields in the form "ATTR_0 = 5" in the class body qualify as static class attributes
"Add assign branch"?
This kind of narration should be in the PR description, not the code comments.
@ -1516,6 +1550,7 @@ impl TopLevelComposer {
ancestors,
methods,
fields,
static_fields, // Introduce static fields for (un)initialization check
"Introduce"?
@ -1621,2 +1656,2 @@
for (f, _, _) in fields {
if !all_inited.contains(f) {
// If a field is uninitialized but also a static class attribute, don't
// throw an error due to uninitialization
Again the code comments should be about the entire code, and not focused on this one patch.
@ -1269,3 +1271,3 @@
.map_err(|e| e.to_display(unifier).to_string())?;
}
ast::StmtKind::AnnAssign { target, annotation, value: None, .. } => {
// Reset value from none since fields in the form "ATTR_0: int32 = 10" need to be initialised
What does "reset" mean?
I don't see
value
being changed in that block of code@ -1294,6 +1297,10 @@ impl TopLevelComposer {
_ if core_config.kernel_ann.is_none() => (annotation, true),
_ => continue, // ignore fields annotated otherwise
};
// If the value node is provided, then it must be a static class attribute
Why must it?
What happens if it isn't?
@ -1339,0 +1355,4 @@
class_static_fields_def.push((*attr, dummy_field_type, true));
class_fields_def.push((*attr, dummy_field_type, true));
style, remove blank line here
@ -1339,0 +1358,4 @@
} else {
return Err(format!(
"same class fields `{}` defined twice (at {})",
fields or field?
Step 1:
From your project repository, check out a new branch and test the changes.Step 2:
Merge the changes and update on Gitea.