diff options
author | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-16 18:29:42 +0000 |
---|---|---|
committer | Gilles Dubochet <gilles.dubochet@epfl.ch> | 2005-12-16 18:29:42 +0000 |
commit | df50e05006b43b007c2587549030d24b5c154398 (patch) | |
tree | 9edfb1fb5b8c04350a00c163cfcdb1fccd79e3aa /test/files/pos/bug267.scala | |
parent | 17e2b1c2a6f69ba74e79c30d1e44195fe732e3e3 (diff) | |
download | scala-df50e05006b43b007c2587549030d24b5c154398.tar.gz scala-df50e05006b43b007c2587549030d24b5c154398.tar.bz2 scala-df50e05006b43b007c2587549030d24b5c154398.zip |
'test-nsc' has been moved to 'test'.
Diffstat (limited to 'test/files/pos/bug267.scala')
-rw-r--r-- | test/files/pos/bug267.scala | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/test/files/pos/bug267.scala b/test/files/pos/bug267.scala new file mode 100644 index 0000000000..d99b1fa1fc --- /dev/null +++ b/test/files/pos/bug267.scala @@ -0,0 +1,55 @@ +package expAbstractData; + +/** A base class consisting of + * - a root trait (i.e. abstract class) `Exp' with an `eval' function + * - an abstract type `exp' bounded by `Exp' + * - a concrete instance class `Num' of `Exp' for numeric literals + */ +trait Base { + type exp <: Exp; + + trait Exp { + def eval: int + } + class Num(v: int): exp extends Exp { + val value = v; + def eval = value + } +} + +object testBase extends Application with Base { + type exp = Exp; + val term = new Num(2); + System.out.println(term.eval); +} + +/** Data extension: An extension of `Base' with `Plus' expressions + */ +trait BasePlus extends Base { + class Plus(l: exp, r: exp): exp extends Exp { + val left = l; + val right = r; + def eval = left.eval + right.eval + } +} + +/** Operation extension: An extension of `Base' with 'show' methods. + */ +trait Show extends Base { + type exp <: Exp1; + + trait Exp1 extends Exp { + def show: String; + } + class Num1(v: int): (exp with Num1) extends Num(v) with Exp1 { + def show = value.toString(); + } +} + +/** Operation extension: An extension of `BasePlus' with 'show' methods. + */ +trait ShowPlus extends BasePlus with Show { + class Plus1(l: exp, r: exp): (exp with Plus1) extends Plus(l, r) with Exp1 { + def show = left.show + " + " + right.show + } +} |