-
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
Fix pretty printer to handle using and erased modifier #17952
Conversation
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. @nicolasstucki: is this a good way to test the output of the tasty printer?
inParens { | ||
if (argFlags.is(Flags.Implicit) && !argFlags.is(Flags.Given)) this += "implicit " | ||
if (argFlags.is(Flags.Given)) this += "using " | ||
if (argFlags.is(Flags.Erased)) this += "erased " |
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.
This one is not correct, erased
can appear on each individual parameter.
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'm hoping 7f9208b fixed this. Do let me know if you think it's not in the right place.
inParens { | ||
if (argFlags.is(Flags.Implicit) && !argFlags.is(Flags.Given)) this += "implicit " | ||
if (argFlags.is(Flags.Given)) this += "using " |
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.
We should not print this if these are the parameters of a lambda. See tests/run-staging/quote-nested-1.check
.
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'm not entirely sure to understand this one. Are you saying that if the arg flag includes given but the outer type is a lambda then the keyword using
is invalid because it should be a contextual function type ?
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.
Oh I see, you meant that the test case failed. I should have checked CI before asking the question above. Will take a look.
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.
0910940 is an attempt to ignore lambdas, although it feels very targeted to me. Let me know what you think of it.
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.
Maybe it would be better to split into printMethdArgsDefs
and printLambdaArgsDefs
as those are different in the grammar.
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.
Addressed in 34c7058. Let me know if that seems more readable to you or not.
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.
Addressed in 34c7058. Let me know if that seems more readable to you or not.
That seems fine to me, but I would deduplicate the two printSeparated
local defs into one private def reused by both methods.
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.
Done via 25f78ea.
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.
We can simplify this to
- if (argFlags.is(Flags.Implicit) && !argFlags.is(Flags.Given)) this += "implicit "
- if (argFlags.is(Flags.Given)) this += "using "
+ if argFlags.is(Flags.Given) then this += "using "
+ else if argFlags.is(Flags.Implicit) then this += "implicit "
There's a conflict with the main branch because #16968 also added a test named |
0910940
to
34c7058
Compare
Sorry for the delay. I have rebased against the latest main branch and −hopefully− addressed the remaining review comment. |
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.
Otherwise LGTM.
inParens { | ||
if (argFlags.is(Flags.Implicit) && !argFlags.is(Flags.Given)) this += "implicit " | ||
if (argFlags.is(Flags.Given)) this += "using " |
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.
Addressed in 34c7058. Let me know if that seems more readable to you or not.
That seems fine to me, but I would deduplicate the two printSeparated
local defs into one private def reused by both methods.
@@ -25,5 +37,17 @@ object Test { | |||
| } | |||
| () | |||
|}""".stripMargin) | |||
|
|||
assert(showTree("A") |
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.
It would be better to move this check into a checkfiles. They are simpler to update/debug if the format changes.
assert(showTree("A") | |
println(showTree("A")) |
Add tests/run-macros/term-show.check
then run scala3-bootstrapped/testCompilatation tests/run-macros/term-show
. Follow the instructions of the error message; the mv
command printed will update the checkfile.
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.
That's what we had before the merge with main, but #16968 used a different style and I followed what was already in main.
@nicolasstucki Should I refactor both asserts to use checkfiles for consistency ?
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.
Yes, it would be good to refactor both. Thank you.
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.
Done in 6afd86d.
@fmonniot could you squash the commits? |
6afd86d
to
056fbc5
Compare
@nicolasstucki done |
The existing pretty printer doesn't handle using/erased keyword, making it a bit misleading when investigating code generated by macros.
This PR add support for those two modifiers