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

Omit more prefixes in non-package module printing #17758

Merged
merged 2 commits into from
Jun 6, 2023

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Jun 2, 2023

When we pretty-print a type in a module class, we end up printing the
module class's symbol. For instance in a reduction failure of
Tuple.Union, we end up printing Tuple.Fold, with Tuple being an internal
(ThisType) reference to the Tuple module class. I tweaked the logic in
fullNameString so that we omit more prefixes, if the module is
non-package (and make it consistent across -Ytest-pickler). The package
part is important, because we want to continue to get "import
scala.concurrent.duration..." instead of "import concurrent.duration..".

When we pretty-print a type in a module class, we end up printing the
module class's symbol.  For instance in a reduction failure of
Tuple.Union, we end up printing Tuple.Fold, with Tuple being an internal
(ThisType) reference to the Tuple module class.  I tweaked the logic in
fullNameString so that we omit more prefixes, if the module is
non-package (and make it consistent across -Ytest-pickler).  The package
part is important, because we want to continue to get "import
scala.concurrent.duration..." instead of "import concurrent.duration..".
@dwijnand dwijnand force-pushed the fix-module-omittable-prefix branch 3 times, most recently from 1cc5c18 to 77ee20b Compare June 3, 2023 13:59
If you refer to a package by name, e.g. `scala.quoted.Quotes`, the type
may have a "quoted" prefix that is a TermRef.  Rather than unravel the
rest of the prefixes, we print the fully package name.
@dwijnand dwijnand force-pushed the fix-module-omittable-prefix branch from 77ee20b to c04bb4f Compare June 3, 2023 16:08
@dwijnand dwijnand marked this pull request as ready for review June 4, 2023 14:40
@dwijnand dwijnand requested a review from nicolasstucki June 4, 2023 14:40
@nicolasstucki nicolasstucki merged commit 2712b40 into scala:main Jun 6, 2023
@@ -106,6 +109,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
if (tp.cls.isAnonymousClass) keywordStr("this")
if (tp.cls.is(ModuleClass)) fullNameString(tp.cls.sourceModule)
else super.toTextRef(tp)
case tp: TermRef if !printDebug =>
if tp.symbol.is(Package) then fullNameString(tp.symbol)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This caused a bit of regression in metals since we are no longer able to omit a package when printing : scalameta/metals#5327

I wonder if you could do a bit more full proof mechanism here so that we always correctly skip prefixes in both metals and compiler 🤔 It's influenced by the imports within metals.

@dwijnand dwijnand deleted the fix-module-omittable-prefix branch July 19, 2023 15:05
@Kordyjan Kordyjan added this to the 3.4.0 milestone Aug 1, 2023
Kordyjan added a commit that referenced this pull request Nov 21, 2023
…18973)

Backports #17758 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
@Kordyjan Kordyjan modified the milestones: 3.4.0, 3.3.2 Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants