From 9ee5025fbd2bca1aac9950e933a1ec81ede5552a Mon Sep 17 00:00:00 2001 From: Andrew Valencik Date: Mon, 21 Feb 2022 14:29:50 -0500 Subject: [PATCH 1/4] Add PolyType to TPrintImpl --- pprint/src-2/TPrintImpl.scala | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pprint/src-2/TPrintImpl.scala b/pprint/src-2/TPrintImpl.scala index 9a16a3f..cfb962f 100644 --- a/pprint/src-2/TPrintImpl.scala +++ b/pprint/src-2/TPrintImpl.scala @@ -221,6 +221,12 @@ object TPrintLowPri{ .map(typePrintImplRec(c)(_, true)) .reduceLeft[fansi.Str]((l, r) => l ++ " with " ++ r) (pre + (if (defs.isEmpty) "" else "{" ++ defs.mkString(";") ++ "}"), WrapType.NoWrap) + case PolyType(typeParams, resultType) => + val params = typeParams.map(t => printArgSyms(t.asInstanceOf[TypeSymbol].typeParams)).mkString("") + ( + params + typePrintImplRec(c)(resultType, true), + WrapType.NoWrap + ) case ConstantType(value) => val pprintedValue = pprint.PPrinter.BlackWhite.copy(colorLiteral = fansi.Color.Green).apply(value.value) From eb802a656d4872cb217d25132143da865a47be32 Mon Sep 17 00:00:00 2001 From: Andrew Valencik Date: Mon, 21 Feb 2022 14:44:06 -0500 Subject: [PATCH 2/4] Add TPrint test for polytype --- pprint/test/src-2/test/pprint/TPrintTests.scala | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pprint/test/src-2/test/pprint/TPrintTests.scala b/pprint/test/src-2/test/pprint/TPrintTests.scala index 66b9c9b..a5ea1ff 100644 --- a/pprint/test/src-2/test/pprint/TPrintTests.scala +++ b/pprint/test/src-2/test/pprint/TPrintTests.scala @@ -235,6 +235,20 @@ object TPrintTests extends TestSuite{ import scala.reflect.runtime.universe._ check[Nothing]("Nothing") } + test("polytype"){ + import scala.language.implicitConversions + type Foo[+A] = Unit + trait Bar[F[_], A] + object Bar { + implicit def anyToBar[A](a: A): Bar[Foo, A] = new Bar[Foo, A] {} + def apply[F[_], A](b: Bar[F, A]): Bar[F, A] = b + } + object Print { + def tprint[A](a: A)(implicit t: pprint.TPrint[A]) = t.render + } + val rendered = Print.tprint(Bar(1)) + assert(rendered.toString() == "Bar[Foo[A], Int]") + } } } From 126b9c197746c57024394b0ca9eac3cd5f176d37 Mon Sep 17 00:00:00 2001 From: Andrew Valencik Date: Sat, 26 Mar 2022 17:23:36 -0400 Subject: [PATCH 3/4] Tweak based on PR feedback --- pprint/src-2/TPrintImpl.scala | 4 ++-- pprint/test/src-2/test/pprint/TPrintTests.scala | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pprint/src-2/TPrintImpl.scala b/pprint/src-2/TPrintImpl.scala index cfb962f..aa7ae18 100644 --- a/pprint/src-2/TPrintImpl.scala +++ b/pprint/src-2/TPrintImpl.scala @@ -222,9 +222,9 @@ object TPrintLowPri{ .reduceLeft[fansi.Str]((l, r) => l ++ " with " ++ r) (pre + (if (defs.isEmpty) "" else "{" ++ defs.mkString(";") ++ "}"), WrapType.NoWrap) case PolyType(typeParams, resultType) => - val params = typeParams.map(t => printArgSyms(t.asInstanceOf[TypeSymbol].typeParams)).mkString("") + val params = printArgSyms(typeParams) ( - params + typePrintImplRec(c)(resultType, true), + params ++ typePrintImplRec(c)(resultType, true), WrapType.NoWrap ) case ConstantType(value) => diff --git a/pprint/test/src-2/test/pprint/TPrintTests.scala b/pprint/test/src-2/test/pprint/TPrintTests.scala index a5ea1ff..f33e3fc 100644 --- a/pprint/test/src-2/test/pprint/TPrintTests.scala +++ b/pprint/test/src-2/test/pprint/TPrintTests.scala @@ -247,7 +247,7 @@ object TPrintTests extends TestSuite{ def tprint[A](a: A)(implicit t: pprint.TPrint[A]) = t.render } val rendered = Print.tprint(Bar(1)) - assert(rendered.toString() == "Bar[Foo[A], Int]") + assert(rendered.toString() == "Bar[[A]Foo[A], Int]") } } } From cb8229fd6b0117bafc2d0c9b9b79f0a6563b6baa Mon Sep 17 00:00:00 2001 From: Andrew Valencik Date: Sun, 27 Mar 2022 09:30:18 -0400 Subject: [PATCH 4/4] Allow Polytypes to be different on 2.12 vs 2.13 --- pprint/test/src-2/test/pprint/TPrintTests.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pprint/test/src-2/test/pprint/TPrintTests.scala b/pprint/test/src-2/test/pprint/TPrintTests.scala index f33e3fc..087399f 100644 --- a/pprint/test/src-2/test/pprint/TPrintTests.scala +++ b/pprint/test/src-2/test/pprint/TPrintTests.scala @@ -246,8 +246,10 @@ object TPrintTests extends TestSuite{ object Print { def tprint[A](a: A)(implicit t: pprint.TPrint[A]) = t.render } - val rendered = Print.tprint(Bar(1)) - assert(rendered.toString() == "Bar[[A]Foo[A], Int]") + val rendered = Print.tprint(Bar(1)).toString() + + val is213Plus = classOf[Seq[Int]].getName != "scala.collection.Seq" + assert(rendered == (if (is213Plus) "Bar[[A]Foo[A], Int]" else "Bar[Foo, Int]")) } } }