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

Missing requirement: self type does not conform to self type A #2214

Closed
olafurpg opened this issue Apr 10, 2017 · 7 comments
Closed

Missing requirement: self type does not conform to self type A #2214

olafurpg opened this issue Apr 10, 2017 · 7 comments

Comments

@olafurpg
Copy link
Contributor

The following code snippet compiles with scalac but not with dotc

package squants
trait Quantity[A <: Quantity[A]] { self: A => }
trait TimeDerivative[A <: Quantity[A]] { self: Quantity[_] => }

Dotty reports the error message

-- Error: tests/pos/missing-requirement/Quantity.scala -------------------------
3 |trait TimeDerivative[A <: Quantity[A]] { self: Quantity[_] => }
  |      ^
  |missing requirement: self type squants.Quantity[_] & squants.TimeDerivative[A] of trait TimeDerivative does not conform to self type A' of required trait Quantity
  |
  |where:    A  is a type in trait TimeDerivative with bounds <: squants.Quantity[LazyRef(A)]
  |          A' is a type in trait Quantity with bounds <: squants.Quantity[LazyRef(A)]

Removing the self: Quantity[_] annotation on TimeDerivative removes the error, and makes the rest of the squants project compile with Dotty 🎉

olafurpg added a commit to olafurpg/squants that referenced this issue Apr 10, 2017
@odersky
Copy link
Contributor

odersky commented Apr 10, 2017

We now check that the self type is closed. See 1754995
in #702. We should still spec this.

@odersky odersky closed this as completed Apr 10, 2017
@olafurpg
Copy link
Contributor Author

What is the recommended migration path for code like TimeDerivative above? Could the error message provide more details?

@odersky
Copy link
Contributor

odersky commented Apr 10, 2017

@olafurpg Let's worry about this if we see several errors of this type. For know I am hoping this is quite a rare case.

@smarter
Copy link
Member

smarter commented Apr 10, 2017

@olafurpg I think you should be able to replace self: Quantity[_] by self: A

@Blaisorblade
Copy link
Contributor

For what it's worth: I'm not sure I understand https://github.com/lampepfl/dotty/pull/702/files#diff-ca3386647f5386b6f70e99f1a9e188cdR3196, but certainly the error "missing requirement" is misleading.

allanrenucci added a commit to dotty-staging/squants that referenced this issue Sep 28, 2017
- Rewrite `apply = parse _` to `apply(x: Any) = parse(x)`:
  scala/scala3#2994
- Remove self type: scala/scala3#2214
allanrenucci added a commit to dotty-staging/squants that referenced this issue Sep 28, 2017
- Rewrite `apply = parse _` to `apply(x: Any) = parse(x)`:
  scala/scala3#2994
- Remove self type: scala/scala3#2214
allanrenucci added a commit to dotty-staging/squants that referenced this issue Apr 18, 2018
- Rewrite `apply = parse _` to `apply(x: Any) = parse(x)`:
  scala/scala3#2994
- Remove self type: scala/scala3#2214
allanrenucci added a commit to dotty-staging/squants that referenced this issue Apr 18, 2018
- Rewrite `apply = parse _` to `apply(x: Any) = parse(x)`:
  scala/scala3#2994
- Remove self type: scala/scala3#2214
allanrenucci added a commit to dotty-staging/squants that referenced this issue Apr 19, 2018
- Rewrite `apply = parse _` to `apply(x: Any) = parse(x)`:
  scala/scala3#2994
- Remove self type: scala/scala3#2214
@SethTisue
Copy link
Member

SethTisue commented Jul 20, 2021

A simpler example that Scala 2 accepts but 3 does not came up on Gitter yesterday:

trait A
trait B { self: A => }
trait C { self: B => }

@dwijnand
Copy link
Member

That's the example in 1754995 (in reverse line order and alphabet letter order) so I take it as expected and intentional.

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

6 participants