Skip to content

Retain position of extension function calls #11574

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 3 commits into from
Mar 5, 2021
Merged

Retain position of extension function calls #11574

merged 3 commits into from
Mar 5, 2021

Conversation

Kordyjan
Copy link
Contributor

@Kordyjan Kordyjan commented Mar 2, 2021

Fixes #11523.

Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on!

I tried with right associative operator extension applications, which still have a zero length span, e.g.

package ext

extension (s: String)
  def :*: (i: Int): (String, Int) = (s, i)

val b = "foo" :*: 23

yields

expect/Extension.scala
----------------------

Summary:
Schema => SemanticDB v4
Uri => Extension.scala
Text => empty
Language => Scala
Symbols => 5 entries
Occurrences => 14 entries

Symbols:
ext/Extension$package. => final package object ext
ext/Extension$package.`:*:`(). => method :*:
ext/Extension$package.`:*:`().(i) => param i
ext/Extension$package.`:*:`().(s) => param s
ext/Extension$package.b. => val method b

Occurrences:
[0:8..0:11): ext <- ext/
[2:0..2:0): <- ext/Extension$package.
[2:11..2:12): s <- ext/Extension$package.`:*:`().(s)
[2:14..2:20): String -> scala/Predef.String#
[3:6..3:9): :*: <- ext/Extension$package.`:*:`().
[3:11..3:12): i <- ext/Extension$package.`:*:`().(i)
[3:14..3:17): Int -> scala/Int#
[3:21..3:27): String -> scala/Predef.String#
[3:29..3:32): Int -> scala/Int#
[3:37..3:37): -> scala/Tuple2.apply().
[3:37..3:38): s -> ext/Extension$package.`:*:`().(s)
[3:40..3:41): i -> ext/Extension$package.`:*:`().(i)
[5:4..5:5): b <- ext/Extension$package.b.
[5:14..5:14): -> ext/Extension$package.`:*:`(). // Note: zero length span here

we should probably watch out for possible interaction with the selectSpan method: https://github.com/lampepfl/dotty/blob/4ed026cb7c0e3e1f97456172e382f199c1aea8da/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala#L515

@Kordyjan
Copy link
Contributor Author

Kordyjan commented Mar 4, 2021

I solved the problem with inline operators by adding an attachment containing the original span of the operator. I don't think there is any nicer way of passing this information for synthesized selects.

@Kordyjan Kordyjan requested a review from bishabosha March 4, 2021 19:44
Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

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

LGTM, I have found an optimisation without attachments

@@ -415,6 +415,15 @@ object Trees {
qualifier.typeOpt.member(name).atSignature(Signature.NotAMethod, name)
case _ =>
super.denot

def nameSpan(using Context): Span =
Copy link
Member

Choose a reason for hiding this comment

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

I tried this which did not need any attachments (I don't think its that important to do the point span for synthetic):

def nameSpan(using Context): Span =
  if span.exists then
    val point = span.point
    if name.toTermName == nme.ERROR then Span(point)
    else if qualifier.span.start > span.start then // right associative
      val realName = name.stripModuleClassSuffix.lastPart
      Span(span.start, span.start + realName.length, point)
    else
      Span(point, span.end, point)
  else span

@bishabosha bishabosha assigned Kordyjan and unassigned bishabosha Mar 4, 2021
@Kordyjan Kordyjan enabled auto-merge March 5, 2021 10:03
- simplify select name span logic
- add test for left associative operators
@Kordyjan Kordyjan merged commit 052913d into scala:master Mar 5, 2021
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Semanticdb: occurence range for extension method application isn't correct
2 participants