Skip to content

Commit 2626e05

Browse files
authored
Add support for Polytypes (#79)
* Add PolyType to TPrintImpl * Add TPrint test for polytype * Tweak based on PR feedback * Allow Polytypes to be different on 2.12 vs 2.13
1 parent f24db51 commit 2626e05

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pprint/src-2/TPrintImpl.scala

+6
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ object TPrintLowPri{
221221
.map(typePrintImplRec(c)(_, true))
222222
.reduceLeft[fansi.Str]((l, r) => l ++ " with " ++ r)
223223
(pre + (if (defs.isEmpty) "" else "{" ++ defs.mkString(";") ++ "}"), WrapType.NoWrap)
224+
case PolyType(typeParams, resultType) =>
225+
val params = printArgSyms(typeParams)
226+
(
227+
params ++ typePrintImplRec(c)(resultType, true),
228+
WrapType.NoWrap
229+
)
224230
case ConstantType(value) =>
225231
val pprintedValue =
226232
pprint.PPrinter.BlackWhite.copy(colorLiteral = fansi.Color.Green).apply(value.value)

pprint/test/src-2/test/pprint/TPrintTests.scala

+16
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,22 @@ object TPrintTests extends TestSuite{
235235
import scala.reflect.runtime.universe._
236236
check[Nothing]("Nothing")
237237
}
238+
test("polytype"){
239+
import scala.language.implicitConversions
240+
type Foo[+A] = Unit
241+
trait Bar[F[_], A]
242+
object Bar {
243+
implicit def anyToBar[A](a: A): Bar[Foo, A] = new Bar[Foo, A] {}
244+
def apply[F[_], A](b: Bar[F, A]): Bar[F, A] = b
245+
}
246+
object Print {
247+
def tprint[A](a: A)(implicit t: pprint.TPrint[A]) = t.render
248+
}
249+
val rendered = Print.tprint(Bar(1)).toString()
250+
251+
val is213Plus = classOf[Seq[Int]].getName != "scala.collection.Seq"
252+
assert(rendered == (if (is213Plus) "Bar[[A]Foo[A], Int]" else "Bar[Foo, Int]"))
253+
}
238254
}
239255
}
240256

0 commit comments

Comments
 (0)