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

Include P in the implicit scope of P.this.type #17088

Merged
merged 1 commit into from
Mar 12, 2023

Conversation

smarter
Copy link
Member

@smarter smarter commented Mar 11, 2023

Before this commit, one compiled but two didn't in:

class Foo[+T]
class Elem:
  def one(a: Elem, x: Foo[a.type]): Int = x.ext
  def two(x: Foo[Elem.this.type]): Int  = x.ext
object Elem:
  extension (x: Foo[Elem]) def ext: Int = 1

This happened because the anchors of the singleton reference a.type includes its underlying type Elem, but Elem.this.type has no anchors at all. This commit changes the definition of anchors to rectify this, which also brings us closer to how Scala 2 behaves.

Before this commit, `one` compiled but `two` didn't in:

    class Foo[+T]
    class Elem:
      def one(a: Elem, x: Foo[a.type]): Int = x.ext
      def two(x: Foo[Elem.this.type]): Int  = x.ext
    object Elem:
      extension (x: Foo[Elem]) def ext: Int = 1

This happened because the anchors of the singleton reference `a.type` includes
its underlying type `Elem`, but `Elem.this.type` has no anchors at all. This
commit changes the definition of anchors to rectify this, which also brings us
closer to how Scala 2 behaves.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants