Consider this code:
val foo = if(true)
new java.lang.Double(4)
else
new java.lang.Integer(4)
The inferred type for foo is:
Number with Comparable[_ >: Double with Integer <: Number with
Comparable[_ >: Double with Integer <: Number]]
So basically the compiler loops on the bounds and aborts after the third recursion.
Why isn’t the following enough?
Number with Comparable[_ >: Double with Integer <: Number]
Not an answer but some clues using implicitly in the REPL. The compiler doesn’t think the types are the same. The inferred type is more specific:
Checking I did the type aliases right:
Types are not the same:
Your type is a super type of the inferred type:
So according to the compiler, it came up with a more specific type – which would be the right thing to do. Note that the use case can be re-created like this:
So I wonder if we can craft a class that is a
DI_SOCbut not aDI, which would illustrateDIandDI_SOCare not the same types and your type is not the least upper bound.Ok, after stepping out for the computer for a bit and then trying again. Here is a class that is a
DI_SOCbut not aDI:Applied to the original use case:
Therefore, the types
SocandInferredare not the same andAxproves thatNumber with Comparable[_ >: Double with Integer <: Number]is not the least upper bound…In other words, there is some room between
Double with Integer <: ? <: Numberbut not much betweenDouble with Integer <: ? <: Number with Comparable[_ >: Double with Integer <: Number]