diff options
-rw-r--r-- | src/reflect/scala/reflect/internal/Depth.scala | 16 | ||||
-rw-r--r-- | test/files/pos/t9018.scala | 16 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/reflect/scala/reflect/internal/Depth.scala b/src/reflect/scala/reflect/internal/Depth.scala index 357abf765f..a330e0accb 100644 --- a/src/reflect/scala/reflect/internal/Depth.scala +++ b/src/reflect/scala/reflect/internal/Depth.scala @@ -21,8 +21,20 @@ final class Depth private (val depth: Int) extends AnyVal with Ordered[Depth] { object Depth { // A don't care value for the depth parameter in lubs/glbs and related operations. - final val AnyDepth = new Depth(Int.MinValue) + // When passed this value, the recursion budget will be inferred from the shape of + // the `typeDepth` of the list of types. + final val AnyDepthValue = -3 + final val AnyDepth = new Depth(AnyDepthValue) + final val Zero = new Depth(0) - @inline final def apply(depth: Int): Depth = if (depth < 0) AnyDepth else new Depth(depth) + // SI-9018: A negative depth is used to signal that we have breached the recursion limit. + // The LUB/GLB implementation will then truncate to Any/Nothing. + // + // We only really need one of these, but we allow representation of Depth(-1) and Depth(-2) + // to mimic the historical choice of 2.10.4. + @inline final def apply(depth: Int): Depth = { + if (depth < AnyDepthValue) AnyDepth + else new Depth(depth) + } } diff --git a/test/files/pos/t9018.scala b/test/files/pos/t9018.scala new file mode 100644 index 0000000000..7fb4cf21b3 --- /dev/null +++ b/test/files/pos/t9018.scala @@ -0,0 +1,16 @@ +object TestObject { + + def m(i: Int): AnyRef = i match { + case 0 => new C() + case 1 => Some(E.A).getOrElse("") + } + + class C extends Ordered[C] { + def compare(that: C): Int = ??? + } + + object E extends Enumeration { + type CharacterClass = Value + val A = Value + } +} |