-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make refined type printing more source compatible #16303
Conversation
on the previous PR, @tgodzik wondered if the formatting could be improved. I think it's out of scope for this PR. Maybe Dale's recent pretty-printing PR (not merged yet) will improve the situation |
we only made two further small tweaks:
if this passes review, we can squash the commits before merge |
marking as draft for now since there are some test failures. probably just need to update some expected outputs to match the new format? |
Most of the failures were indeed due to some unexpected output. I've updated the expected output for those. The catchall case was actually being hit by the tests for capture checking. I lack knowledge about the implementation details to explain that. For now I've updated this case to return an empty string which makes the tests pass. Some example output with the previous implementation:
|
@@ -112,7 +112,13 @@ class PlainPrinter(_ctx: Context) extends Printer { | |||
|
|||
/** String representation of a refinement */ | |||
protected def toTextRefinement(rt: RefinedType): Closed = | |||
(refinementNameString(rt) ~ toTextRHS(rt.refinedInfo)).close | |||
val keyword = rt.refinedInfo match { | |||
case _: TypeRef => "val " |
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 suggest this case to be made below TypeBounds and turn it to TypeProxy
, so it can work with e.g. val x: List[Int]
, which is AppliedType
, type proxy should cover most cases - such as annotated types Foo { val x: String @unchecked }
.
(refinementNameString(rt) ~ toTextRHS(rt.refinedInfo)).close | ||
val keyword = rt.refinedInfo match { | ||
case _: TypeRef => "val " | ||
case _: ExprType | _: MethodType => "def " |
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.
there could also be PolyType, e.g. def bar: Foo { def foo[T <: Any](t: T): String } = ???
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.
for this case, Foo
must be a class that already defines foo
as a polymorphic method
Thanks for your comments and suggestions @bishabosha. I've updated the code & tests accordingly. This also solves the issue with |
@SethTisue Shall I rebase on the main branch, squash the commits and force push this branch? |
Is it just me that's bothered that |
No, I prefer the latter one as well. However we previously said it to be out of scope for this PR: #16303 (comment) . This PR only adds keywords. Perhaps #16277 did bring some improvements already? Otherwise I propose to improve that in a separate PR. |
Yes please! |
2f9cd62
to
d8ae923
Compare
Co-authored-by: Denis Zolkin <[email protected]>
d8ae923
to
b2f4cbe
Compare
@SethTisue It took a few tries, but now it's ready to be merged I think 😉 |
Yay! |
Fixes #12939
Supersedes #13698