Skip to content

When registering Ident use, consider the original span for synthetics #20575

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,12 @@ object ExtractSemanticDB:
case tree: Ident =>
if tree.name != nme.WILDCARD then
val sym = tree.symbol.adjustIfCtorTyparam
registerUseGuarded(None, sym, tree.span, tree.source)
val span =
if tree.span.isSynthetic then
// use synthetic's definition span instead of the original span, if exists
localBodies.get(tree.symbol).map(_.span).filter(_.exists).getOrElse(tree.span)
else tree.span
registerUseGuarded(None, sym, span, tree.source)
case tree: Select =>
val qual = tree.qualifier
val qualSpan = qual.span
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class SyntheticsExtractor:

val visited = collection.mutable.HashSet[Tree]()

def tryFindSynthetic(tree: Tree)(using Context, SemanticSymbolBuilder, TypeOps): Option[s.Synthetic] =
/** Attempt to format the given tree as a Synthetic apply, if applicable. */
def tryFindSynthetic(tree: Apply | TypeApply)(using Context, SemanticSymbolBuilder, TypeOps): Option[s.Synthetic] =
extension (synth: s.Synthetic)
def toOpt: Some[s.Synthetic] = Some(synth)

Expand Down
2 changes: 1 addition & 1 deletion tests/semanticdb/expect/NamedApplyBlock.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object NamedApplyBlockMethods/*<-example::NamedApplyBlockMethods.*/ {
val local/*<-example::NamedApplyBlockMethods.local.*/ = 1
def foo/*<-example::NamedApplyBlockMethods.foo().*/(a/*<-example::NamedApplyBlockMethods.foo().(a)*/: Int/*->scala::Int#*/ = 1, b/*<-example::NamedApplyBlockMethods.foo().(b)*/: Int/*->scala::Int#*/ = 2, c/*<-example::NamedApplyBlockMethods.foo().(c)*/: Int/*->scala::Int#*/ = 3): Int/*->scala::Int#*/ = a/*->example::NamedApplyBlockMethods.foo().(a)*/ +/*->scala::Int#`+`(+4).*/ b/*->example::NamedApplyBlockMethods.foo().(b)*/ +/*->scala::Int#`+`(+4).*/ c/*->example::NamedApplyBlockMethods.foo().(c)*/
def baseCase/*<-example::NamedApplyBlockMethods.baseCase().*/ = foo/*->example::NamedApplyBlockMethods.foo().*/(local/*->example::NamedApplyBlockMethods.local.*/, c/*->example::NamedApplyBlockMethods.foo().(c)*/ = 3)
def recursive/*<-example::NamedApplyBlockMethods.recursive().*/ = foo/*->example::NamedApplyBlockMethods.foo().*/(local/*->example::NamedApplyBlockMethods.local.*/, c/*->example::NamedApplyBlockMethods.foo().(c)*/ = foo/*->example::NamedApplyBlockMethods.foo().*/(local/*->example::NamedApplyBlockMethods.local.*/, c/*->example::NamedApplyBlockMethods.foo().(c)*/ = 3))
def recursive/*<-example::NamedApplyBlockMethods.recursive().*/ = foo/*->example::NamedApplyBlockMethods.foo().*//*->local1*/(local/*->example::NamedApplyBlockMethods.local.*/, c/*->example::NamedApplyBlockMethods.foo().(c)*/ = foo/*->example::NamedApplyBlockMethods.foo().*/(local/*->example::NamedApplyBlockMethods.local.*/, c/*->example::NamedApplyBlockMethods.foo().(c)*/ = 3))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def recursive/*<-example::NamedApplyBlockMethods.recursive().*/ = foo/*->example::NamedApplyBlockMethods.foo().*//*->local1*/(local/*->example::NamedApplyBlockMethods.local.*/, c/*->example::NamedApplyBlockMethods.foo().(c)*/ = foo/*->example::NamedApplyBlockMethods.foo().*/(local/*->example::NamedApplyBlockMethods.local.*/, c/*->example::NamedApplyBlockMethods.foo().(c)*/ = 3))
def recursive/*<-example::NamedApplyBlockMethods.recursive().*/ = foo/*->example::NamedApplyBlockMethods.foo().*/(local/*->example::NamedApplyBlockMethods.local.*/, c/*->example::NamedApplyBlockMethods.foo().(c)*/ = foo/*->example::NamedApplyBlockMethods.foo().*/(local/*->example::NamedApplyBlockMethods.local.*/, c/*->example::NamedApplyBlockMethods.foo().(c)*/ = 3))

That local doesn't exist in the source code so we should not add it to occurrences

}

object NamedApplyBlockCaseClassConstruction/*<-example::NamedApplyBlockCaseClassConstruction.*/ {
Expand Down
3 changes: 2 additions & 1 deletion tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,7 @@ Uri => NamedApplyBlock.scala
Text => empty
Language => Scala
Symbols => 43 entries
Occurrences => 41 entries
Occurrences => 42 entries

Symbols:
example/NamedApplyBlockCaseClassConstruction. => final object NamedApplyBlockCaseClassConstruction extends Object { self: NamedApplyBlockCaseClassConstruction.type => +6 decls }
Expand Down Expand Up @@ -2911,6 +2911,7 @@ Occurrences:
[5:28..5:29): c -> example/NamedApplyBlockMethods.foo().(c)
[6:6..6:15): recursive <- example/NamedApplyBlockMethods.recursive().
[6:18..6:21): foo -> example/NamedApplyBlockMethods.foo().
[6:18..6:21): foo -> local1
[6:22..6:27): local -> example/NamedApplyBlockMethods.local.
[6:29..6:30): c -> example/NamedApplyBlockMethods.foo().(c)
[6:33..6:36): foo -> example/NamedApplyBlockMethods.foo().
Expand Down
Loading