Skip to content

Unnecessary accessors generated by compile-time reflection #24356

@szeiger

Description

@szeiger

Tested with 3.7.3.

The simple overload of Symbol.newClass in the reflect API,

      @experimental def newClass(
        owner: Symbol,
        name: String,
        parents: Symbol => List[TypeRepr],
        decls: Symbol => List[Symbol],
        selfType: Option[TypeRepr],
        clsFlags: Flags,
        clsPrivateWithin: Symbol,
        conParams: List[(String, TypeRepr)]
      ): Symbol

which does not require or allow constructor parameter flags, produces unnecessary getters for constructor parameters that are promoted to fields (and uses these setters when reading them).

These getters disappear when using the overload that allows you to specify constructor flags and setting them to Flags.PrivateLocal.

The same is true for private fields. While fields declared in Scala code as either private var or (using deprecated syntax) private[this] var are treated identically and do not result in setters or getters, fields generated by the reflect API have to be marked explicitly with Flags.PrivateLocal to avoid unnecessary accessors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugstat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions