Skip to content

Conversation

roterEmil
Copy link
Collaborator

@roterEmil roterEmil commented Feb 1, 2024

The FieldAssignabilityAnalysis tries to determine whether one can consider a field as "final", i.e. if only one known value exists for this field. This can be the case even when the field is not itself final, i.e. when there is a singular write in the constructor that publishes a single value.

However, one can read the field before this singular write in the constructor, yielding the default value of the field (whether explicitly given or not). Thus, two known values of this field exist, and we cannot simply consider the field as having one value anymore.

We need to think about this some more!

@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.

} 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

@roterEmil roterEmil requested a review from errt January 10, 2025 15:35
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

@johannesduesing johannesduesing added this to the Release 6.0.0 milestone Sep 12, 2025
@maximilianruesch maximilianruesch changed the title fixed prematurely read issue of assignability analysis Fix assignability analysis for prematurely read fields Sep 16, 2025
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.

4 participants