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

Upper Bound not unified #4043

Closed
scabug opened this issue Nov 28, 2010 · 6 comments
Closed

Upper Bound not unified #4043

scabug opened this issue Nov 28, 2010 · 6 comments

Comments

@scabug
Copy link

scabug commented Nov 28, 2010

In the following code, H1 and H0 are both Int, but the types are not unified.

object TypeParam {
  trait GC[K[_ <: H0], H0]

  trait PA[H1] {
    type Apply[A <: H1] = Any
  }

  // error:
  // kinds of the type arguments ([A <: H1]Any,Int) do not conform to the expected kinds of the type parameters (type K,type H0) in trait GC.
  // [A <: H1]Any's type parameters do not match type K's expected parameters:
  // type A's bounds >: Nothing <: H1 are stricter than type _'s declared bounds >: Nothing <: H0
  type a = GC[PA[Int]#Apply, Int]
}

Substituting H1 to Int manually allows compilation:

  trait PA[H1] {
    type Apply[A <: Int] = Any
  }

What versions of the following are you using?
Scala: 2.8.1, 2.9.0-SNAPSHOT

See also r23383

@scabug
Copy link
Author

scabug commented Nov 28, 2010

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

@scabug
Copy link
Author

scabug commented Nov 29, 2010

@retronym said:
Motivation:

https://gist.github.com/719247

https://gist.github.com/719352

The workaround is to express the abstract types as members, rather than parameters. this is a bit more verbose.

@scabug
Copy link
Author

scabug commented Jul 30, 2015

@retronym said:
This is the "as seen from" operation that loses track of the fact that H1 = Int

Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_51).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'.          **
** scala.tools.nsc._ has been imported      **
** global._, definitions._ also imported    **
** Try  :help, :vals, power.<tab>           **

scala> :paste -raw
// Entering paste mode (ctrl-D to finish)

object TypeParam {
  trait GC[K[_ <: H0], H0]

  trait PA[H1] {
    type Apply[A <: H1] = Any
  }
 }

// Exiting paste mode, now interpreting.

warning: there was one feature warning; re-run with -feature for details

scala> val pInt = typeOf[TypeParam.PA[Int]]
pInt: $r.intp.global.Type = TypeParam.PA[Int]

scala> val Apply = pInt member TypeName("Apply")
Apply: $r.intp.global.Symbol = type Apply

scala> pInt memberType Apply
res0: $r.intp.global.Type = [A <: H1]Any

@scabug
Copy link
Author

scabug commented Jul 30, 2015

@retronym said:
I believe this is an oversight in eta expansion of type aliases. Here's an attempt at a fix: retronym/scala#16

@scabug
Copy link
Author

scabug commented Jul 30, 2015

@retronym said:
Darn, the fix doesn't bootstrap.

Related discussion: https://groups.google.com/d/msg/scala-internals/45XNa6WqvlU/hSWHFF66CQAJ

@diesalbla
Copy link

This still fails in Scala 2.12.8 (using REPL), but works in the current Scala 2.13.x branch.

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

3 participants