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

Cannot write type members in phantom types #3121

Closed
nicolasstucki opened this issue Sep 14, 2017 · 2 comments
Closed

Cannot write type members in phantom types #3121

nicolasstucki opened this issue Sep 14, 2017 · 2 comments

Comments

@nicolasstucki
Copy link
Contributor

As found in #2040

object MyPhantom extends Phantom {
  type Foo = this.Any { type Member = Int }
}

will fail with

  type Foo = this.Any { type Member = Int }
             ^^^^^^^^
illegal trait inheritance: superclass Object does not derive from trait Any's super<nonsensical><none></nonsensical>

The issue probably that there is an Object added to the type of this.Any { type Member = Int } when desugaring.

@nicolasstucki
Copy link
Contributor Author

A quick patch in Checking.checkTraitInheritance to avoid the error showed that the following code works.

object MyPhantom extends Phantom {
  type Foo = this.Any { type M }

  def a: Foo { type M = Int } = assume
  def b: Foo { type M = Boolean } = assume

  def foo(a: Foo { type M = Int }): Unit = ()

  foo(a)
  foo(b) // fails as expected
}

nicolasstucki added a commit to nicolasstucki/dotty that referenced this issue Oct 3, 2017
nicolasstucki added a commit to nicolasstucki/dotty that referenced this issue Oct 3, 2017
@nicolasstucki
Copy link
Contributor Author

Phantom will be removed in #3410

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants