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

fixed prematurely read issue of assignability analysis #190

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

roterEmil
Copy link
Collaborator

No description provided.

@roterEmil roterEmil requested a review from errt February 1, 2024 10:36
Copy link
Collaborator

@errt errt left a comment

Choose a reason for hiding this comment

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

Apart from the comments in the code, the tests fail with this PR, please have a look why and make sure tests succeed, as otherwise this can't be merged.


if (field.isPublic)
if (field.isPublic && !field.isFinal)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it be easier and more readable to just wrap the entire section into a separate if (!field.isFinal)?

} else {
receiverVar.isDefined && receiverVar.get.definedBy != SelfReferenceParameter
}
if (method.isInitializer && method.classFile == field.classFile) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this part of the code needs documentation to understand what all of the different conditions do

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still not documented


C() {
super();
//this.b(this);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this commented out? If it is needed, reinstantiate it, if it is unnecessary, remove it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was the example Marc gave me. I will remove the outcommented code as well as the function b()

static int n = 5;

public static void main(String[] args) {
System.out.println("Value A.X before constructor:" + PrematurelyReadOfFinalField.n);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these printlns necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will remove them.

@roterEmil roterEmil requested a review from errt January 10, 2025 15:35
// in different branches
if (!definedMethod.definedMethod.isConstructor)
return true
}; // Otherwise: field is written in multiple locations, thus must be assignable
Copy link
Collaborator

Choose a reason for hiding this comment

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

Move semicolon to the return please

if (index > 0 && stmts(index).isPutStatic) {
stmts(index).asPutStatic.value.asVar
} else if (
index > 0 && stmts(index).isPutField && stmts(index).asPutField.value.asVar.value.isArrayValue.isYes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please document this case, it is unclear why it is like this. In particular, why do we take the value from all PutStatic instructions, but only PutField instructions with array values? And why can't we rely on the receiverVar in all cases? Shouldn't it be same the asPut{Static,Field}.value.asVar anyway?

if (index > 0 && stmts(index).isPutStatic) {
stmts(index).asPutStatic.value.asVar
} else if (
index > 0 && stmts(index).isPutField && stmts(index).asPutField.value.asVar.value.isArrayValue.isYes
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if it is unknown whether the value is an array value? (Not sure if this can happen here, but still, one should think about it)

} else {
receiverVar.isDefined && receiverVar.get.definedBy != SelfReferenceParameter
}
if (method.isInitializer && method.classFile == field.classFile) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Still not documented

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