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

Compiler fails strangely on some higher-order kinds #7902

Closed
scabug opened this issue Oct 8, 2013 · 4 comments
Closed

Compiler fails strangely on some higher-order kinds #7902

scabug opened this issue Oct 8, 2013 · 4 comments

Comments

@scabug
Copy link

scabug commented Oct 8, 2013

Consider the following example code:

import scala.language.higherKinds

object Bug {
  object Definition {
    final class Tag[+W[D1, C1, M1[X1, +Y1] <: Map[X1, Y1]]]
    private val instance = new Tag[Nothing]

    def ofType[W[D2, C2, M2[X2, +Y2] <: Map[X2, Y2]]]: Tag[W] = instance
    type InSeq[D3, C3, M3[X3, +Y3] <: Map[X3, Y3]] = IndexedSeq[M3[D3, C3]]
    val result = Definition.ofType[Definition.InSeq]
  }
  object Usage {
    val result = Definition.ofType[Definition.InSeq]
  }
}

The definitions of "result" objects are the same. However, the "result" of Usage compiles, while "result" of Definition does not.

The whole effect is very unstable when regarding the circumstances. For example, incremental compilation under IntelliJ IDEA may report successful compilation of the otherwise buggy code when the previous compilation was OK.

@scabug
Copy link
Author

scabug commented Oct 8, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7902?orig=1
Reporter: Maxim Buzdalov (MaxBuzz)
Affected Versions: 2.10.2, 2.10.3
Other Milestones: 2.11.0-M7

@scabug
Copy link
Author

scabug commented Oct 8, 2013

Maxim Buzdalov (MaxBuzz) said:
The precise compilation error is:

Bug.scala:10: error: kinds of the type arguments (Bug.Definition.InSeq) do not conform to the expected kinds of the type parameters (type W).
Bug.Definition.InSeq's type parameters do not match type W's expected parameters:
<none> is invariant, but type Y2 is declared covariant
<none>'s bounds<notype> are stricter than type X2's declared bounds >: Nothing <: Any, <none>'s bounds<notype> are stricter than type Y2's declared bounds >: Nothing <: Any
    val result = Definition.ofType[Definition.InSeq]
                                  ^
one error found

@scabug
Copy link
Author

scabug commented Oct 9, 2013

@retronym said:
Whittled down:

import scala.language.higherKinds

object Bug {
  class Tag[W[M1[X1]]]

  def ofType[W[M2[X2]]]: Tag[W] = ???
  type InSeq  [M3[X3]] = Some[M3[Any]]

  // fail
  val x = ofType[InSeq]

  // okay
  val y: Any = ofType[InSeq]
  object T {
    val z = ofType[InSeq]
  }
}

@scabug
Copy link
Author

scabug commented Oct 9, 2013

@retronym said (edited on Oct 9, 2013 11:34:37 AM UTC):
The workaround is to annotate the return type of the val.

Here's a fix for Scala 2.11:

scala/scala#3025

Thanks for taking the time to produce such a clean and small bug report!

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