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

Type projection alias fails with higher kinded types with type bounds #11621

Open
jdrphillips opened this issue Jul 9, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@jdrphillips
Copy link

commented Jul 9, 2019

The following code fails:

object Testing {

  trait One[A] {
    type Two[B <: A] = Altogether[A, B]
  }

  trait Altogether[A, B <: A]

  type Test = One[Int]#Two[Int]
}

with error

type arguments [Int] do not conform to type Two's type parameter bounds [B <: A]

However, the following code succeeds:

object Testing {

  trait One[A] {
    trait Two[B <: A]
  }

  type Test = One[Int]#Two[Int]
}

I don't see a reason why the second passes and the first does not. The following compiles successfully:

type Test = Altogether[Int, Int]

I would expect both Altogether[Int, Int] and One[Int]#Two[Int] to compile.

Behaviour observed on both scala 2.12.8 and 2.13.0

@SethTisue

This comment has been minimized.

Copy link
Member

commented Jul 9, 2019

Dotty accepts your first example.

@joroKr21

This comment has been minimized.

Copy link

commented Jul 18, 2019

Looks like before checking the bounds we dealiased One[Int]#Two to [B <: Int]Altogether[Int, B] and in the process lost the information that the prefix was One[Int], so asSeenFrom could not see that A = Int.

The folklore for preventing dealiasing is:

  trait One[A] {
    type Two[B <: A] >: Altogether[A, B] <: Altogether[A, B]
  }

  trait Altogether[A, B <: A]
  type Test = One[Int]#Two[Int]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.