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

Kind conformance passes in trait, fails in subclass with same type argument #9337

Closed
scabug opened this issue May 31, 2015 · 6 comments · Fixed by scala/scala#9404
Closed

Comments

@scabug
Copy link

scabug commented May 31, 2015

import scala.language.higherKinds

trait TypePreservingFn[T[X <: T[X]]]

trait Validator[T, This <: Validator[T,This]]

trait Foo[T] {

  type `Validator[T]`[This <: Validator[T, This]] = Validator[T, This]

  val f: TypePreservingFn[`Validator[T]`] = ???  // compiles

}

class Bar[T] extends Foo[T] {

  val g: TypePreservingFn[`Validator[T]`] = ???  // does not compile

}
@scabug
Copy link
Author

scabug commented May 31, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9337?orig=1
Reporter: Robin Green (ST_robin_green)
Affected Versions: 2.11.6

@scabug
Copy link
Author

scabug commented Jun 1, 2015

@adriaanm said:
That's some fancy naming for Validator[T] -- never seen that trick before!

Both definitions should be accepted. Workaround is to duplicate the type alias, or to factor our the type constructor used for the bound on T's X.

This compiles:

class Bar[U] extends Foo[U] {
  type VU[This <: Validator[U, This]] = Validator[U, This]
  val g: TypePreservingFn[VU] = ???  // does not compile
}

@scabug
Copy link
Author

scabug commented Jun 2, 2015

@retronym said (edited on Jun 2, 2015 3:26:49 AM UTC):
@adriaanm: here's a patch that makes this work: scala/scala@2.11.x...retronym:ticket/9337

But I fear my head might explode trying to write the commit comment. Perhaps you have a better chance at that :)

@scabug
Copy link
Author

scabug commented Feb 13, 2017

@retronym said:
Another test case from #10186 for the same problem. This is also fixed by my patch.

trait Foo {
  type A
  type F[P <: A]
}
 
object Test {
  def noop[A1, F1[P <: A1]]: Unit = ()

  def f(foo: Foo): Unit = {
    noop[foo.A, foo.F] // does not compile
  }
}

@joroKr21
Copy link
Member

But I fear my head might explode trying to write the commit comment. Perhaps you have a better chance at that :)

This is what I came up with: scala/scala@1f4611d
Higher-kinded bounds have found their way again.
Unfortunately it doesn't fix this bug but it does fix #10186

@joroKr21
Copy link
Member

Here is the issue:

  trait AliasTypeRef extends NonClassTypeRef {
    require(sym.isAliasType, sym)

    override def dealias    = if (typeParamsMatchArgs) betaReduce.dealias else super.dealias
    override def narrow     = normalize.narrow
    override def prefix     = if (this ne normalize) normalize.prefix else pre
    override def termSymbol = if (this ne normalize) normalize.termSymbol else super.termSymbol
    override def typeSymbol = if (this ne normalize) normalize.typeSymbol else sym

the prefix of Validator[T] is the prefix of Validator instead of Bar

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

Successfully merging a pull request may close this issue.

4 participants