From e465571a4e1dcdd76d888da1e93108e0ee71ce85 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Wed, 2 Mar 2011 02:55:44 +0000 Subject: Added cycle detection to getParts. --- src/compiler/scala/tools/nsc/typechecker/Implicits.scala | 4 ++++ test/files/neg/bug4221.check | 6 ++++++ test/files/neg/bug4221.scala | 10 ++++++++++ 3 files changed, 20 insertions(+) create mode 100644 test/files/neg/bug4221.check create mode 100644 test/files/neg/bug4221.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 6d36c77b28..655e5dfe09 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -724,11 +724,15 @@ trait Implicits { */ private def companionImplicits(tp: Type): Infoss = { val partMap = new LinkedHashMap[Symbol, Type] + val seen = mutable.HashSet[Type]() // cycle detection /** Enter all parts of `tp` into `parts` set. * This method is performance critical: about 2-4% of all type checking is spent here */ def getParts(tp: Type) { + if (seen(tp)) + return + seen += tp tp match { case TypeRef(pre, sym, args) => if (sym.isClass) { diff --git a/test/files/neg/bug4221.check b/test/files/neg/bug4221.check new file mode 100644 index 0000000000..471332e3c1 --- /dev/null +++ b/test/files/neg/bug4221.check @@ -0,0 +1,6 @@ +bug4221.scala:8: error: type mismatch; + found : Unit + required: Wrapper[S] + def wrap[S <: Cl#Sub[S]](v: S): Wrapper[S] = { + ^ +one error found diff --git a/test/files/neg/bug4221.scala b/test/files/neg/bug4221.scala new file mode 100644 index 0000000000..0a8b8add18 --- /dev/null +++ b/test/files/neg/bug4221.scala @@ -0,0 +1,10 @@ +class Cl { + class Sub[TheSub <: Sub[TheSub]] +} + +case class Wrapper[T](v: T) + +object O { + def wrap[S <: Cl#Sub[S]](v: S): Wrapper[S] = { + } +} -- cgit v1.2.3