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

case class with higher kinded type parameter generates buggy canEqual, triggers kind error since v2.11.0-M1-246-g46e8ece #9331

Closed
scabug opened this issue May 27, 2015 · 12 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented May 27, 2015

% scalac-hash 46e8eceecc5b5f6b49075550e54f035126fc256a sandbox/test.scala
sandbox/test.scala:9: error: kinds of the type arguments (Proxy[PP]) do not conform to the expected kinds of the type parameters (type P) in class Stuff.
Proxy[PP]'s type parameters do not match type P's expected parameters:
trait Proxy has one type parameter, but type P has one
case class Stuff[+P[PP <: Proxiable] <: Proxy[PP]](content: P[Data])
           ^
one error found
% ~/code/scala scalac-hash 46e8eceecc5b5f6b49075550e54f035126fc256a~1 sandbox/test.scala
% ~/code/scala cat sandbox/test.scala
import scala.language.higherKinds
trait Proxiable {
  def source: String
}
trait Proxy[+T <: Proxiable] {
  def source: String
}
case class Data(source: String) extends Proxiable
case class Stuff[+P[PP <: Proxiable] <: Proxy[PP]](content: P[Data])

Reported: https://groups.google.com/forum/#!topic/scala-user/QiQ0AvVwYm8

@scabug
Copy link
Author

scabug commented May 27, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9331?orig=1
Reporter: @retronym
See #8039

@scabug
Copy link
Author

scabug commented May 27, 2015

@retronym said:
See also: scala/scala#3519, which has since touched the code that introduced the regression.

@scabug
Copy link
Author

scabug commented May 27, 2015

@retronym said:

scalac-hash 46e8eceecc5b5f6b49075550e54f035126fc256a~1 -Xdev sandbox/test.scala
topic/require-java-8 ~/code/scala scalac-hash 46e8eceecc5b5f6b49075550e54f035126fc256a -Xdev sandbox/test.scala
warning: !!! isSubType2(Proxy[PP], P, _) compares HK type with proper type
warning: !!! isSubType2(Proxy[PP], P, _) compares HK type with proper type
sandbox/test.scala:9: error: kinds of the type arguments (Proxy[PP]) do not conform to the expected kinds of the type parameters (type P) in class Stuff.
Proxy[PP]'s type parameters do not match type P's expected parameters:
trait Proxy has one type parameter, but type P has one
case class Stuff[+P[PP <: Proxiable] <: Proxy[PP]](content: P[Data])
           ^
two warnings found
one error found

@scabug
Copy link
Author

scabug commented May 27, 2015

@adriaanm said:
It looks to me like it's forming a type it shouldn't form: Proxy[PP] means nothing in the body of canEqual (PP is not in scope)

    <synthetic> def canEqual(x$1: Any): Boolean = x$1.$isInstanceOf[Stuff[Proxy[PP]]]();

@scabug
Copy link
Author

scabug commented May 27, 2015

@retronym said:
Here's a smaller test case:

import scala.language.higherKinds
trait Proxy[+T]
case class Stuff[+P[PP] <: Proxy[PP]]()

The most self contained workaround seems to be manually implementing canEqual.

import scala.language.higherKinds
trait Proxiable {
  def source: String
}
trait Proxy[+T <: Proxiable] {
  def source: String
}
case class Data(source: String) extends Proxiable
case class Stuff[+P[PP <: Proxiable] <: Proxy[PP]](content: P[Data]) {
  def canEqual(x$1: Any): Boolean = x$1 match { case _: Stuff[_] => true; case _ => false}
}

@scabug
Copy link
Author

scabug commented May 27, 2015

@retronym said:
See also #8039, which would make it possible to write (or synthesize) isInstanceOf[Stuff[_]] without getting a kind error.

@scabug
Copy link
Author

scabug commented May 27, 2015

@scabug
Copy link
Author

scabug commented Jun 26, 2015

Fred (fred) said:
I'm the author of the ML report.

I saw this didn't make it in 2.11.7 and was wondering if there is anything I could do to help get it in 2.11.8?

Thank you

@scabug
Copy link
Author

scabug commented Jun 29, 2015

@adriaanm said:
It looks like we just need to submit the PR in time for 2.11.8 based on the WIP, and convince ourselves it's safe to do so in a 2.11.x release. I've gone over the patch a couple of times now, and it looks like it should be good to go.

@scabug
Copy link
Author

scabug commented Sep 6, 2015

Fred (fred) said:
FYI, I built my own scala distribution based on scala 2.11.7 into which I merged the above mentioned patch. Using it, I could successfully compile everything... and tests pass.

@scabug
Copy link
Author

scabug commented Mar 14, 2016

Fred (fred) said:
Could this be considered for merging into scala 2.12?

We would love not to be stuck with scala 2.10 and akka 2.3 until late 2016 (planned release of scala 2.11.9 according to http://scala-lang.org/news/2.11.8/).

Thanks

@scabug
Copy link
Author

scabug commented Jan 10, 2017

@adriaanm said:
Fix for 2.11.9: scala/scala#5633

@scabug scabug closed this as completed Mar 14, 2017
@scabug scabug added the critical label Apr 7, 2017
@scabug scabug added this to the 2.11.9 milestone Apr 7, 2017
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

No branches or pull requests

2 participants