bug icon indicating copy to clipboard operation
bug copied to clipboard

Type bounds checks are deferred?

Open dima-starosud opened this issue 7 years ago • 1 comments

Hello team, please consider following code snippet.

Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 9.0.1).
Type in expressions for evaluation. Or try :help.

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

  trait Target {
    type Value = Int
    type Apply[F[_]] = F[Value]
  }

  trait Box {
    type Inner
  }

  type Unbox[B <: Box] = B#Inner

// Exiting paste mode, now interpreting.

defined trait Target
defined trait Box
defined type alias Unbox

scala> type Result1 = Target#Apply[Unbox] // will not compile
<console>:13: error: kinds of the type arguments (Unbox) do not conform to the expected kinds of the type parameters (type F).
Unbox's type parameters do not match type F's expected parameters:
type B's bounds <: Box are stricter than type _'s declared bounds >: Nothing <: Any
       type Result1 = Target#Apply[Unbox] // will not compile
                             ^

scala> type Result2 = Target#Apply[({type R[V] = Unbox[V]})#R] // shouldn't compile as well
defined type alias Result2

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

  trait Target {
    trait Value
    type Apply[F[_]] = F[Value]
  }

// Exiting paste mode, now interpreting.

defined trait Target

scala> type Result1 = Target#Apply[Unbox] // also shouldn't compile?
defined type alias Result1

scala>

Should I expect all the cases to not compile?

dima-starosud avatar Dec 28 '17 11:12 dima-starosud

"fixed in Scala 3" in the sense that B#Inner was deliberately made illegal

SethTisue avatar Mar 03 '25 15:03 SethTisue