diff options
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/bug81.scala | 4 | ||||
-rw-r--r-- | test/files/pos/bug85.scala | 8 | ||||
-rw-r--r-- | test/files/pos/bug91.scala | 6 | ||||
-rw-r--r-- | test/files/pos/bug93.scala | 4 | ||||
-rw-r--r-- | test/files/pos/compound.scala | 9 | ||||
-rw-r--r-- | test/files/pos/gui.scala | 99 | ||||
-rw-r--r-- | test/files/pos/thistype.scala | 14 | ||||
-rw-r--r-- | test/files/pos/traits.scala | 42 |
8 files changed, 186 insertions, 0 deletions
diff --git a/test/files/pos/bug81.scala b/test/files/pos/bug81.scala new file mode 100644 index 0000000000..20fd604974 --- /dev/null +++ b/test/files/pos/bug81.scala @@ -0,0 +1,4 @@ +class A { + val b: A#B = new B; + class B {} +} diff --git a/test/files/pos/bug85.scala b/test/files/pos/bug85.scala new file mode 100644 index 0000000000..e018afb6ee --- /dev/null +++ b/test/files/pos/bug85.scala @@ -0,0 +1,8 @@ +object A { + case class B(c: C) { + class C; + } + class C; + val b: B = new B(new C()); + val c: C = b.c; +} diff --git a/test/files/pos/bug91.scala b/test/files/pos/bug91.scala new file mode 100644 index 0000000000..e05365caf4 --- /dev/null +++ b/test/files/pos/bug91.scala @@ -0,0 +1,6 @@ +class Bug { + def main(args: Array[String]) = { + var msg: String = _; // no bug if "null" instead of "_" + val f: PartialFunction[Any, unit] = { case 42 => msg = "coucou" }; + } +} diff --git a/test/files/pos/bug93.scala b/test/files/pos/bug93.scala new file mode 100644 index 0000000000..f3441fe9c3 --- /dev/null +++ b/test/files/pos/bug93.scala @@ -0,0 +1,4 @@ +object Bug { + def f(def cond: Boolean) = while (cond == false) {}; + // no bug with "false == cond" +} diff --git a/test/files/pos/compound.scala b/test/files/pos/compound.scala new file mode 100644 index 0000000000..60890f9102 --- /dev/null +++ b/test/files/pos/compound.scala @@ -0,0 +1,9 @@ +abstract class A { type T } + +abstract class B { val xz: Any } + +abstract class Test { + var yy: A with B { type T; val xz: T } = null; + var xx: A with B { type T; val xz: T } = null; + xx = yy; +} diff --git a/test/files/pos/gui.scala b/test/files/pos/gui.scala new file mode 100644 index 0000000000..27863f7368 --- /dev/null +++ b/test/files/pos/gui.scala @@ -0,0 +1,99 @@ +object Geom { + trait Shape; + case class Point(x: int, y: int) extends Shape; + case class Rectangle(ll: Point, ur: Point) extends Shape { + def inset(delta: int) = + Rectangle(Point(ll.x - delta, ll.y - delta), Point(ur.x + delta, ur.y + delta)); + } +} + +object Color { + type Color = int; + val black = 0x000000; + val grey = 0x808080; +} + +trait Screen { + type Color = int; + def drawRect(r: Geom.Rectangle, c: Color): unit; + def fillRect(r: Geom.Rectangle, c: Color): unit; +} + +object DummyScreen extends Screen { + def drawRect(r: Geom.Rectangle, c: Color): unit = + System.out.println("draw " + r + " with " + c); + def fillRect(r: Geom.Rectangle, c: Color): unit = + System.out.println("fill " + r + " with " + c); +} + +object GUI { + + object Controller { + def addMouseCtl(c: MouseCtl) = () + } + + trait Glyph { + def getRect: Geom.Rectangle; + def setLoc(p: Geom.Point): unit; + def draw() = System.out.println("draw " + this); + } + + class Label(scr: Screen, p: Geom.Point, name: String) extends Glyph { + private var origin = p; + def getRect = Geom.Rectangle(origin, origin).inset(10); + def setLoc(p: Geom.Point) = { origin = p } + } + + trait Ctl { + def getGlyph: Glyph; + def enable(b: Boolean): this.type; + } + + trait MouseCtl with Ctl { + def mouseDown(p: Geom.Point): unit; + } + + abstract class Button(scr: Screen, p: Geom.Point, name: String) + extends Glyph with MouseCtl { + var enabled: boolean = false; + val label = new Label(scr, p, name); + + /* Glyph methods */ + override def draw(): unit = { + if (enabled) scr.drawRect(getRect, Color.black) + else scr.fillRect(getRect, Color.grey); + label.draw(); + } + def setLoc(p: Geom.Point) = label.setLoc(p); + def getRect = label.getRect.inset(-2); + + /* Ctl methods */ + def enable(b: boolean): this.type = { enabled = b; draw(); this } + def getGlyph = label; + final def mouseDown(p: Geom.Point): unit = + if (enabled) doit() else System.out.println("button is disabled"); + + /* deferred method to be specified by client */ + def doit(): unit; + } +} + +object GUIClient { + + class Application { + def quit() = System.out.println("application exited"); + } + + class QuitButton (scr: Screen, p: Geom.Point, name: String, a: Application) + extends GUI.Button(scr, p, name) { + def doit(): unit = a.quit(); + } + + def main(args: Array[String]) = { + val b = new QuitButton( + DummyScreen, Geom.Point(1, 1), "quit", new Application); + b.draw(); + b.enable(true).mouseDown(Geom.Point(1, 2)); + } +} + diff --git a/test/files/pos/thistype.scala b/test/files/pos/thistype.scala new file mode 100644 index 0000000000..8c0ba209be --- /dev/null +++ b/test/files/pos/thistype.scala @@ -0,0 +1,14 @@ +object Test { + + class Ctl { + def enable: this.type = { System.out.println("enable"); this } + } + + class MouseCtl extends Ctl { + def mouseDown(x: int, y: int): unit = { System.out.println("mouse down"); } + } + + def main(args: Array[String]) = + new MouseCtl().enable.mouseDown(1, 2); + +} diff --git a/test/files/pos/traits.scala b/test/files/pos/traits.scala new file mode 100644 index 0000000000..5fdf4b342e --- /dev/null +++ b/test/files/pos/traits.scala @@ -0,0 +1,42 @@ +object Test { + type Color = int; + trait Shape { + override def equals(other: Any) = true; + } + trait Bordered extends Shape { + val thickness: int; + override def equals(other: Any) = other match { + case that: Bordered => this.thickness == that.thickness; + case _ => false + } + } + trait Colored extends Shape { + val color: Color; + override def equals(other: Any) = other match { + case that: Colored => this.color == that.color; + case _ => false + } + } + trait BorderedColoredShape extends Shape with Bordered with Colored { + override def equals(other: Any) = other match { + case that: BorderedColoredShape => + super.equals(that) && + super[Bordered].equals(that) && + super[Colored].equals(that) + case _ => false + } + } + + val bcs1 = new BorderedColoredShape { + val thickness = 1; + val color = 0; + } + val bcs2 = new BorderedColoredShape { + val thickness = 2; + val color = 0; + } + System.out.println(bcs1 == bcs1); + System.out.println(bcs1 == bcs2); +} + + |