Doesn't `Metadata` note which primary constructor ...
# compiler
m
Doesn't
Metadata
note which primary constructor parameters are also properties?
u
No, this information is not stored in the metadata. And I think it shouldn't, because your program should likely work exactly the same way on both
Copy code
class A(val x: String)
and
Copy code
class A(x: String) {
    val x: String = x
}
Storing the "is primary constructor property" flag in the metadata is of course possible, but would lead to a way for annotation processors and others to use that flag in a way that would introduce a difference between the two above programs. Related issue: https://youtrack.jetbrains.com/issue/KT-8849
m
Makes sense what you say. My idea was that by default JSON decoding automatically uses all primary constructor parameters as properties to decode and all of these parameters which are also properties for encoding. It indeed doesn't really matter if they're in the constructor or not. But for now I'm decided on relying on
!Flag.PropertyAccessor.IS_NOT_DEFAULT(getterFlags)
to select which properties are encoded automatically by default.
👍 1