From 935ba9ba3021b518dab8f22c1e5d897865777aab Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 27 Dec 2011 07:00:07 -0800 Subject: Consecutive type application. The parser through I think a quirk of history would not allow back to back type applications, like expr[T1, T2][T3, T4] Now it does, meaning the only thing it can: val n0 = Partial[immutable.HashMap][String][Int] ++ Seq(("a", 1)) val n1 = Partial.apply[immutable.HashMap].apply[String].apply[Int] ++ Seq(("a", 1)) assert(n0 == n1) --- test/files/run/type-currying.scala | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/files/run/type-currying.scala (limited to 'test/files/run/type-currying.scala') diff --git a/test/files/run/type-currying.scala b/test/files/run/type-currying.scala new file mode 100644 index 0000000000..717e0763a3 --- /dev/null +++ b/test/files/run/type-currying.scala @@ -0,0 +1,45 @@ +import scala.collection.{ mutable, immutable, generic } +import generic.CanBuildFrom + +object Partial { + type KnownContainer[CC[K, V] <: collection.Map[K, V]] = { + def values[V] : KnownValues[CC, V] + def apply[K] : KnownKeys[CC, K] + } + type KnownKeys[CC[K, V] <: collection.Map[K, V], K] = { + def apply[V](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]): CC[K, V] + } + type KnownValues[CC[K, V] <: collection.Map[K, V], V] = { + def apply[K](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]): CC[K, V] + } + + def apply[CC[K, V] <: collection.Map[K, V]] : KnownContainer[CC] = new { + def values[V] : KnownValues[CC, V] = new { + def apply[K](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]) = cbf().result + } + def apply[K] = new { + def apply[V](implicit cbf: CanBuildFrom[_, (K, V), CC[K, V]]) = cbf().result + } + } +} + +object Test { + val m = Partial[immutable.TreeMap] + val m1 = m[String] + val m2 = m[Int][Int] + + val mutableBippy = Partial[mutable.HashMap][String][Int] + mutableBippy("abc") = 55 + + val immutableBippy = Partial[immutable.HashMap].values[Int] + def make[T](xs: T*) = immutableBippy[T] ++ xs.zipWithIndex + + val n0 = Partial[immutable.HashMap][String][Int] ++ Seq(("a", 1)) + val n1 = Partial.apply[immutable.HashMap].apply[String].apply[Int] ++ Seq(("a", 1)) + + def main(args: Array[String]): Unit = { + println(mutableBippy) + make('a' to 'z': _*).toList.sorted foreach println + assert(n0 == n1) + } +} -- cgit v1.2.3 From 008a781f49feb567833e9347ff9d293defeafe6d Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Fri, 30 Dec 2011 23:02:44 -0800 Subject: More uniformity for the parser. Fixing consecutive type application made it more obvious there was another missing bit of the parser, type application following function application. This should (and now does) work: object F { def apply[T] = List[T]() } def g() = F g()[String] --- src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 8 ++++---- test/files/run/type-currying.scala | 13 +++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'test/files/run/type-currying.scala') diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 00ac3976a9..db97dd3475 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1533,12 +1533,12 @@ self => case LBRACKET => val t1 = stripParens(t) t1 match { - case Ident(_) | Select(_, _) => - var tapp: Tree = t1 + case Ident(_) | Select(_, _) | Apply(_, _) => + var app: Tree = t1 while (in.token == LBRACKET) - tapp = atPos(tapp.pos.startOrPoint, in.offset)(TypeApply(tapp, exprTypeArgs())) + app = atPos(app.pos.startOrPoint, in.offset)(TypeApply(app, exprTypeArgs())) - simpleExprRest(tapp, true) + simpleExprRest(app, true) case _ => t1 } diff --git a/test/files/run/type-currying.scala b/test/files/run/type-currying.scala index 717e0763a3..f9764c64f0 100644 --- a/test/files/run/type-currying.scala +++ b/test/files/run/type-currying.scala @@ -43,3 +43,16 @@ object Test { assert(n0 == n1) } } + +class A { + object Foo { + def apply[T] = Bar + } + object Bar { + def apply() = Foo + } + + def f() = Foo + def g = f()[Int]()[String]() + def h = Foo[Foo.type]()[Foo.type]() +} -- cgit v1.2.3