Skip to content

Fix #6415: Enable REPL code completion for opaque types #6429

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

Merged
merged 1 commit into from
May 3, 2019

Conversation

anatoliykmetyuk
Copy link
Contributor

opaque type T = Int desugars to (roughly):

opaque type T = T.T
object T {
  opaque type T = Int
}

So one opaque type T desugars to two opaque type T's. One of them is synthetic – the first one. It shadows the second one during code completion due to the fact that it has the same span.

@anatoliykmetyuk anatoliykmetyuk requested a review from smarter May 2, 2019 15:16
@anatoliykmetyuk
Copy link
Contributor Author

(the first commit is from #6414)

@anatoliykmetyuk anatoliykmetyuk marked this pull request as ready for review May 2, 2019 15:17
@@ -820,7 +820,7 @@ object desugar {
val moduleName = tdef.name.toTermName
val localRef = Select(Ident(moduleName), tdef.name)
localRef.pushAttachment(SuppressAccessCheck, ())
val aliasType = cpy.TypeDef(tdef)(rhs = completeForwarder(localRef))
val aliasType = cpy.TypeDef(tdef)(rhs = completeForwarder(localRef)).withSpan(Span(MaxOffset))
Copy link
Member

Choose a reason for hiding this comment

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

Synthetic trees should always have a position where the start and the end are identical, that's how we distinguish them from user-written trees, but they should still point to the closest position where they were defined in the source code (otherwise, error messages involving them will point to the wrong line) so you should do .withSpan(tdef.span.startPos)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, this also works

The completion did not work because the desugared version of the
opaque type's definition shared the span with its private definition
inside the companion object.
@anatoliykmetyuk anatoliykmetyuk merged commit 9a2d2d1 into scala:master May 3, 2019
@anatoliykmetyuk anatoliykmetyuk deleted the i6415 branch May 3, 2019 10:59
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.

2 participants