diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-12-03 22:20:13 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-12-03 22:20:13 +1000 |
commit | a1ee57da54eff4fe372e304fb5695941a70211c6 (patch) | |
tree | fa7cf81acff51b61243383262883309e090fd81e | |
parent | 56b9f068f144dca67685dc884420ca67251df4c4 (diff) | |
parent | 081b82fdba37734f28c00417bfad12171a096710 (diff) | |
download | scala-a1ee57da54eff4fe372e304fb5695941a70211c6.tar.gz scala-a1ee57da54eff4fe372e304fb5695941a70211c6.tar.bz2 scala-a1ee57da54eff4fe372e304fb5695941a70211c6.zip |
Merge pull request #4178 from retronym/ticket/9018
SI-9018 Fix regression: cycle in LUBs
-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 + } +} |