Skip to content

Correct offset for single-string interpolation #8629

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 6 commits into from
Mar 30, 2020

Conversation

martijnhoekstra
Copy link
Contributor

Fixes #8627

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

fix is a big word -- I'm not sure where it's pointing now
is any better than where it was.
@@ -7,8 +7,8 @@ scala> xml"
| ';' expected, but eof found
scala> xml""
1 | xml""
| ^
| value xml is not a member of StringContext
| ^
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is now aligned with the implementation, but it still looks wrong to me. Analogous to

scala> "".xml
1 |"".xml
  |^^^^^^
  |value xml is not a member of String

I would have expected

scala> "".xml
1 |xml""
  |^^^^^
  |value xml is not a member of StringContext

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, that would be the correct position.

Change Desugar.scala#L1668 to

        Apply(Select(Apply(scalaDot(nme.StringContext).withSpan(tree.span), strs), id), elems)

@nicolasstucki nicolasstucki self-assigned this Mar 30, 2020
Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

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

This is clearly the correct way to assign the positions.

@@ -7,8 +7,8 @@ scala> xml"
| ';' expected, but eof found
scala> xml""
1 | xml""
| ^
| value xml is not a member of StringContext
| ^
Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, that would be the correct position.

Change Desugar.scala#L1668 to

        Apply(Select(Apply(scalaDot(nme.StringContext).withSpan(tree.span), strs), id), elems)

@martijnhoekstra
Copy link
Contributor Author

@nicolasstucki that led to some semanticdb updateExpect stuff that I'm not sure looks entirely right, even though I have no idea who it should look.

@nicolasstucki
Copy link
Contributor

It looks kind of fine. @bishabosha could you have a look at the diffs in the semanticdb tests?

@@ -1665,7 +1665,7 @@ object desugar {
case t => t
}
// This is a deliberate departure from scalac, where StringContext is not rooted (See #4732)
Apply(Select(Apply(scalaDot(nme.StringContext), strs), id), elems)
Apply(Select(Apply(scalaDot(nme.StringContext).withSpan(tree.span), strs), id), elems)
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also try this variant to see if the semanticdb test keep on working without changes.

Suggested change
Apply(Select(Apply(scalaDot(nme.StringContext).withSpan(tree.span), strs), id), elems)
Apply(Select(Apply(scalaDot(nme.StringContext), strs), id).withSpan(tree.span), elems)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Giving that a try, you get 31e9464

No more truncated string segments, but I have no idea whether that was a problem in the first place or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks better. Maybe @bishabosha can tell us which one is better. If not I would go with this one.

Copy link
Member

Choose a reason for hiding this comment

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

I think its better now that the actual method call has a span the length of the interpolator prefix, rather than empty but i guess its not matched exactly to the prefix, but there are other desugaring anomalies like extension methods.
So this is good.

@nicolasstucki nicolasstucki merged commit 25c0305 into scala:master Mar 30, 2020
@nicolasstucki
Copy link
Contributor

Thank you @martijnhoekstra

@martijnhoekstra martijnhoekstra deleted the interpolatedPos branch March 30, 2020 15:28
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.

First string part of interpolation is mispositioned
4 participants