Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upNo longer emit accessors for private fields #8286
Open
Conversation
This comment has been minimized.
This comment has been minimized.
Linting for unused privates would need to be fixed, as now there are no more unused accessors, only the field which is accessed in the constructor - should be doable, as linting works correctly for |
For value class parameters, the accessor is used as the `unbox` method in other classes. There are a few assumptions in the compiler for that method being present. Private case class parameters are excluded because an accessor is generated anyway to support extraction. We could change the backend avoid going through the accessor within the class. Mark object fields static in CleanUp, because: ``` class C { def f = C.x } object C { private val x = 0 } ``` The field `x` is made `notPrivate` to allow access from C. In the backend, the field is emitted static. However, if only the backend phase adds the `static` flag to the symbol, it's not there yet when emitting `C`, and therefore the field access has the wrong opcode.
This comment has been minimized.
This comment has been minimized.
I can imagine that this could break some reflection based frameworks that are looking for annotated getter methods that we no longer emit. So maybe we need to expose this as a compiler setting. One of the options could be to emit them for annotated fields. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
lrytz commentedJul 31, 2019
•
edited
Except for value class and case class parameters.
For value class parameters, the accessor is used as the
unbox
method inother classes. There are a few assumptions in the compiler for that method
being present.
Private case class parameters are excluded because an accessor is generated
anyway to support extraction. We could change the backend avoid going through
the accessor within the class.
Mark object fields static in CleanUp, because:
The field
x
is madenotPrivate
to allow access from C. In thebackend, the field is emitted static. However, if only the backend
phase adds the
static
flag to the symbol, it's not there yet whenemitting
C
, and therefore the field access has the wrong opcode.