-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
Although this is not a type a user of Scala 2 can write, |
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]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be
assert(rendered.toString() == "Bar[Foo[A], Int]") | |
assert(rendered.toString() == "Bar[[+A]Foo[A], Int]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've switched to Bar[[A]Foo[A], Int]
for 2.13+, ditching the variance annotation as I don't think anything in PPrint uses the variance.
pprint/src-2/TPrintImpl.scala
Outdated
@@ -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("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be
val params = typeParams.map(t => printArgSyms(t.asInstanceOf[TypeSymbol].typeParams)).mkString("") | |
val params = printArgSyms(typeParams) |
In scalajs 2.12.13 only, we are now failing with:
I unfortunately can't run the failing tests locally. When I try
I do have |
Update: I was able to run the 2.12 tests locally with just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
Thank you for the contribution!
This PR adds a new case for
PolyType
in TPrintImpl.Hopefully this resolves:
MatchError
inTPrint
macro expansion onPolyType
#76I've used @mrdziuban's scastie reproduction as a test case.
Disclaimer: I don't actually know what these PolyType's should look like.
We can test with the console via
mill -i "pprint.jvm[2.13.4].console"
and see what the compiler gives us:As shown, the compiler prints
Bar[[+A]Foo[A],Int]
instead of ourBar[Foo[A], Int]
.I feel like the[+A]Foo[A]
is not usually how we'd write this, but happy to be corrected.Update Mar 27th:
We now render Polytypes differently in Scala 2.12 versus 2.13:
Scala 2.13:
Bar[[A]Foo[A], Int]
Scala 2.12:
Bar[Foo, Int]
Disclaimer: I do not know if this is reasonable. It just so happens to work with minimal changes to PPrint.