Skip to content

ParamForwarding: questions #783

@DarkDimius

Description

@DarkDimius

https://github.com/lampepfl/dotty/blob/master/src/dotty/tools/dotc/transform/ParamForwarding.scala#L22

/** For all parameter accessors
 *
 *      val x: T = ...
 *
 *  if
 *  (1) x is forwarded in the supercall to a parameter that's also named `x`
 *  (2) the superclass parameter accessor for `x` is accessible from the current class
 *  change the accessor to
 *
 *    def x: T = super.x.asInstanceOf[T]
 *
 *  Do the same also if there are intermediate inaccessible parameter accessor forwarders.
 *  The aim of this transformation is to avoid redundant parameter accessor fields.
 */

I have several questions to what this phase does:

  1. Why do names matter?
  2. if indeed name has not changed, is not it better to remove def entirely? Than virtual dispatch will do the same that def x: T = super.x.asInstanceOf[T] does. (I guess the answer is that types could be different, but I want to make sure that there are no other reasons)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions