-
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
Allow SourceCodePrinter to show type without prefixes #9716
Comments
The We could have a use second printing mode that shows a simpler representation of the code as with the Refined/PlainPrinter do. The difference is that this mode would not ensure that the code can be copy-pasted and recompiled (needed by decompiler), but this alternate mode is fine debugging purposes. At the start, we used the |
It makes sense! I don't that my particular use case was ever predicted.
Do you think a simple flag is enough (print prefix normally, but don't print with flag on) or should it be a separate class altogether like Refined vs Plain printer? I mnagaed to get the result I needed with removing just a bit of code and inlining it all for now. |
Maybe we can try that. The question there is: which prefixes can be elided?
|
The flag should be enough |
We have the same problem in error messages: they always print the fully qualified type which can sometimes makes them hard to read. The proper thing to do would be to take into account the imports available at the current point to know which prefixes can be elided, but no one has tried to implement that so far. |
Before adding new functionality, we should probably make the current behaviour of SourceCodePrinter more consistent. I played with it a bit and I got quite surprised with the results I got.
It looks like type aliases are expanded if type parameters are passed to them but not otherwise. Also type constructors are displayed as type lambdas but only if they're not type aliases. What should be the correct behaviour? |
In general, we do not want to dealias to avoid losing some higher-level abstraction that may be simpler to read. The alias for Note that |
Dealiasing seems to be a problem also in other places and there have been already some attempts to solve this be realiasing in some contexts (see: https://contributors.scala-lang.org/t/pre-sip-realiasing-types-in-error-messages/4362/2). I'm not sure if something similar could be easily implemented in SourceCodePrinter as it uses a mutable buffer. |
The best behavior is to print the types as the compiler typed it. In some situations the compiler will dealias some but not other. That is not part of what we control. This may change over time. |
Fixed in #10172 We can now use |
While working with worksheets it turned out to be more useful to just use the show method on Type using it from macros like:
Unfortunately by default it prints the whole type with the prefix, so we would get
scala.collection.immuntable.List
instead of justList
.I was thinking of just adding an additional option to drop the prefixes there, which should not be much effort. Alternatively, we could reuse the PlainPrinter. However, while I feel confident I could work on adding an additional option I feel like consolidating the printers might be something I will not have the time to work on.
Any opinions? CC @odersky @bishabosha
The text was updated successfully, but these errors were encountered: