Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Polytypes #79

Merged
merged 4 commits into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pprint/src-2/TPrintImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = printArgSyms(typeParams)
(
params ++ typePrintImplRec(c)(resultType, true),
WrapType.NoWrap
)
case ConstantType(value) =>
val pprintedValue =
pprint.PPrinter.BlackWhite.copy(colorLiteral = fansi.Color.Green).apply(value.value)
Expand Down
16 changes: 16 additions & 0 deletions pprint/test/src-2/test/pprint/TPrintTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,22 @@ 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)).toString()

val is213Plus = classOf[Seq[Int]].getName != "scala.collection.Seq"
valencik marked this conversation as resolved.
Show resolved Hide resolved
assert(rendered == (if (is213Plus) "Bar[[A]Foo[A], Int]" else "Bar[Foo, Int]"))
}
}
}