From b2455fcc388e35125adc527a4b4f8021f0b95523 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 24 Jul 2006 15:38:59 +0000 Subject: --- .../scala/tools/nsc/typechecker/Namers.scala | 14 ++++- test/files/pos/orderedpoints.scala | 30 ----------- test/files/pos/viewtest3.scala | 60 ---------------------- 3 files changed, 13 insertions(+), 91 deletions(-) delete mode 100644 test/files/pos/orderedpoints.scala delete mode 100644 test/files/pos/viewtest3.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 87d2dcf400..42f073402e 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -383,9 +383,21 @@ trait Namers requires Analyzer { private def templateSig(templ: Template): Type = { val clazz = context.owner; - val parents = typer.parentTypes(templ) map (p => if (p.tpe.isError) AnyRefClass.tpe else p.tpe); + def checkParent(tpt: Tree): Type = { + val tp = tpt.tpe + if (tp.symbol == context.owner) { + context.error(tpt.pos, ""+tp.symbol+" inherits itself"); + AnyRefClass.tpe + } else if (tp.isError) { + AnyRefClass.tpe + } else { + tp + } + } + val parents = typer.parentTypes(templ) map checkParent val decls = new Scope(); new Namer(context.make(templ, clazz, decls)).enterSyms(templ.body); + ClassInfoType(parents, decls, clazz) } diff --git a/test/files/pos/orderedpoints.scala b/test/files/pos/orderedpoints.scala deleted file mode 100644 index f972028bce..0000000000 --- a/test/files/pos/orderedpoints.scala +++ /dev/null @@ -1,30 +0,0 @@ -package test; - -class Point1(x: int) extends Object with Ordered[Point1] { - val xCoord = x; - def compare [b >: Point1 <% Ordered[b]](that: b): int = that match { - case that1: Point1 => this.xCoord.compare(that1.xCoord) - case _ => -that.compare(this) - } -} -class Point2(x: int, y: int) extends Point1(x) with Ordered[Point2] {} -/* - val yCoord = y; - override def compareTo [b >: Point2 <% Ordered[b]](that: b): int = that match { - case that1: Point2 => - val r = super.compareTo(that1); - if (r == 0) this.yCoord.compareTo(that1.yCoord) else r - case _ => -that.compareTo(this) - } -} -object Test extends Application { - val p1 = new Point1(1); - val q1 = new Point1(2); - System.out.println(p1 < q1); - val p2 = new Point2(1, 2); - val q2 = new Point2(1, 3); - System.out.println(p2 < q2); - System.out.println(p1 < q2); - System.out.println(p2 < q1); -} -*/ diff --git a/test/files/pos/viewtest3.scala b/test/files/pos/viewtest3.scala deleted file mode 100644 index aa7b2ec539..0000000000 --- a/test/files/pos/viewtest3.scala +++ /dev/null @@ -1,60 +0,0 @@ -package testview; - -trait Tree[+a <% Ordered[a]] { - def insert[c >: b, b >: a <: c](x: b)(implicit d: c => Ordered[c]): Tree[b] - def elements: List[a] -} - -object Empty extends Tree[All] { - def insert[c >: b, b >: a <: c](x: b)(implicit d: c => Ordered[c]): Tree[b] = - new Node(x, Empty, Empty); - def elements: List[All] = List(); -} - -class Node[a <% Ordered[a]](elem: a, l: Tree[a], r: Tree[a]) extends Tree[a] { - def insert[c >: b, b >: a <: c](x: b)(implicit d: c => Ordered[c]): Tree[b] = - if (x == elem) this - else if (x < elem) new Node(elem, l insert x, r) - else new Node(elem, l, r insert x); - def elements: List[a] = - l.elements ::: List(elem) ::: r.elements -} - -case class Str(elem: String) extends Ordered[Str] { - def compare[b >: Str <% Ordered[b]](that: b): int = that match { - case that1: Str => this.elem compare that1.elem - case _ => -(that compare this) - } -} - -object Test { -// import O.view; - - private def toCharList(s: String): List[Char] = - if (s.length() == 0) List() - else s.charAt(0) :: toCharList(s.substring(1)); - - def main(args: Array[String]) = { - { - var t: Tree[String] = Empty; - for (val s <- args) { - t = t insert s - } - System.out.println(t.elements) - } - { - var t: Tree[Str] = Empty; - for (val s <- args) { - t = t insert Str(s) - } - System.out.println(t.elements) - } - { - var t: Tree[List[char]] = Empty; - for (val s <- args) { - t = t insert toCharList(s) - } - System.out.println(t.elements) - } - } -} -- cgit v1.2.3