Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial support for super accessors (fix #100) #326

Merged
merged 1 commit into from
Jan 19, 2019

Conversation

xeno-by
Copy link
Contributor

@xeno-by xeno-by commented Jan 19, 2019

While working on #100, I realized that we're in trouble.

In order to generate super accessors, a Scala compiler needs to go through method bodies, typecheck super selections and see which of them qualify. At the moment, Rsc doesn't look into method bodies at all, which looks like a game over.

All's not lost, however. Since super accessors are pretty exotic, our users may be willing to accept additional notational overhead to express them. A workaround along these lines has been implemented in this pull request. For example, let's look at #100:

trait T1 {
  def x: Int = ???
}

trait T2 extends T1 {
  def y: Int = super.x
}
13:31 ~/Projects/2126/sandbox (HEAD)$ s -Xprint:refchecks
[[syntax trees at end of                 refchecks]] // Test.scala
package <empty> {
  abstract trait T1 extends scala.AnyRef {
    def /*T1*/$init$(): Unit = {
      ()
    };
    def x: Int = scala.Predef.???
  };
  abstract trait T2 extends AnyRef with T1 {
    <superaccessor> <artifact> private def super$x: Int;
    def /*T2*/$init$(): Unit = {
      ()
    };
    def y: Int = T2.this.super$x
  }
}

In order to nudge Rsc into generating a ScalaSignature entry for super$x, we can adopt the following notation (due to some reason, Scalac needs to know which base class the superaccessor is referring to, and we encode that in an additional parameter section):

trait T1 {
  def x: Int = ???
}

trait T2 extends T1 {
  private def super$x(self: T1): Int = ???
  def y: Int = super.x
}

I've explored a prettier notation for the same thing: private def super$x: Int = super[T1].x, but unfortunately it doesn't work when the type in brackets is a class (due to some reason, Scalac says "implementation restriction: traits may not select fields or methods from super[C] where C is a class").

@xeno-by xeno-by added this to the M6 milestone Jan 19, 2019
@xeno-by xeno-by self-assigned this Jan 19, 2019
@xeno-by xeno-by mentioned this pull request Jan 19, 2019
@xeno-by xeno-by merged commit 16ab61c into twitter:master Jan 19, 2019
@xeno-by xeno-by deleted the topic/100 branch January 19, 2019 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

1 participant