Skip to content

Commit 21e39e0

Browse files
committed
Exclude synthetic symbols from occurrences
1 parent 8d8777e commit 21e39e0

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ class ExtractSemanticDB extends Phase:
313313
else
314314
Span(span.start)
315315

316-
registerOccurrence(sname, finalSpan, SymbolOccurrence.Role.DEFINITION, treeSource)
316+
if sym.occursInSource then
317+
registerOccurrence(sname, finalSpan, SymbolOccurrence.Role.DEFINITION, treeSource)
317318
if !sym.is(Package) then
318319
registerSymbol(sym, symkinds)
319320

compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ object Scala3:
128128
def isSyntheticWithIdent(using Context): Boolean =
129129
sym.is(Synthetic) && !sym.isAnonymous && !sym.name.isEmptyNumbered
130130

131+
/** Check if the symbol occurs in source code */
132+
def occursInSource(using Context): Boolean =
133+
!sym.is(Synthetic) && !sym.name.is(NameKinds.EvidenceParamName)
134+
131135
def symbolInfo(symkinds: Set[SymbolKind])(using LinkMode, TypeOps, SemanticSymbolBuilder, Context): SymbolInformation =
132136
val sname = sym.symbolName
133137
val signature = sym.info.toSemanticSig(sym)

tests/semanticdb/expect/Methods.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Methods/*<-example::Methods#*/[T/*<-example::Methods#[T]*/] {
1515
def m6/*<-example::Methods#m6().*/(x/*<-example::Methods#m6().(x)*/: Int/*->scala::Int#*/) = ???/*->scala::Predef.`???`().*/
1616
def m6/*<-example::Methods#m6(+1).*/(x/*<-example::Methods#m6(+1).(x)*/: List/*->example::Methods#List#*/[T/*->example::Methods#[T]*/]) = ???/*->scala::Predef.`???`().*/
1717
def m6/*<-example::Methods#m6(+2).*/(x/*<-example::Methods#m6(+2).(x)*/: scala.List/*->scala::package.List#*/[T/*->example::Methods#[T]*/]) = ???/*->scala::Predef.`???`().*/
18-
def m7/*<-example::Methods#m7().*/[U/*<-example::Methods#m7().[U]*//*<-example::Methods#m7().(evidence$1)*/: Ordering/*->scala::math::Ordering#*//*->example::Methods#m7().[U]*/](c/*<-example::Methods#m7().(c)*/: Methods/*->example::Methods#*/[T/*->example::Methods#[T]*/], l/*<-example::Methods#m7().(l)*/: List/*->example::Methods#List#*/[U/*->example::Methods#m7().[U]*/]) = ???/*->scala::Predef.`???`().*/
18+
def m7/*<-example::Methods#m7().*/[U/*<-example::Methods#m7().[U]*/: Ordering/*->scala::math::Ordering#*//*->example::Methods#m7().[U]*/](c/*<-example::Methods#m7().(c)*/: Methods/*->example::Methods#*/[T/*->example::Methods#[T]*/], l/*<-example::Methods#m7().(l)*/: List/*->example::Methods#List#*/[U/*->example::Methods#m7().[U]*/]) = ???/*->scala::Predef.`???`().*/
1919
def `m8()./*<-example::Methods#`m8().`().*/`() = ???/*->scala::Predef.`???`().*/
2020
class `m9()./*<-example::Methods#`m9().`#*/`
2121
def m9/*<-example::Methods#m9().*/(x/*<-example::Methods#m9().(x)*/: `m9().`/*->example::Methods#`m9().`#*/) = ???/*->scala::Predef.`???`().*/

tests/semanticdb/expect/Synthetic.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Synthetic/*<-example::Synthetic#*/ {
3030
null.asInstanceOf/*->scala::Any#asInstanceOf().*/[Int/*->scala::Int#*/ => Int/*->scala::Int#*/]/*->scala::Function1#apply().*/(2)
3131
}
3232

33-
class J/*<-example::Synthetic#J#*/[T/*<-example::Synthetic#J#[T]*//*<-example::Synthetic#J#evidence$1.*/: Manifest/*->scala::Predef.Manifest#*//*->example::Synthetic#J#[T]*/] { val arr/*<-example::Synthetic#J#arr.*/ = Array/*->scala::Array.*/.empty/*->scala::Array.empty().*/[T/*->example::Synthetic#J#[T]*/]/*->example::Synthetic#J#evidence$1.*/ }
33+
class J/*<-example::Synthetic#J#*/[T/*<-example::Synthetic#J#[T]*/: Manifest/*->scala::Predef.Manifest#*//*->example::Synthetic#J#[T]*/] { val arr/*<-example::Synthetic#J#arr.*/ = Array/*->scala::Array.*/.empty/*->scala::Array.empty().*/[T/*->example::Synthetic#J#[T]*/]/*->example::Synthetic#J#evidence$1.*/ }
3434

3535
class F/*<-example::Synthetic#F#*/
3636
implicit val ordering/*<-example::Synthetic#ordering.*/: Ordering/*->scala::package.Ordering#*/[F/*->example::Synthetic#F#*/] = ???/*->scala::Predef.`???`().*/

tests/semanticdb/metac.expect

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,7 +2252,7 @@ Uri => Methods.scala
22522252
Text => empty
22532253
Language => Scala
22542254
Symbols => 82 entries
2255-
Occurrences => 157 entries
2255+
Occurrences => 156 entries
22562256

22572257
Symbols:
22582258
example/Methods# => class Methods [typeparam T ] extends Object { self: Methods[T] => +44 decls }
@@ -2396,7 +2396,6 @@ Occurrences:
23962396
[16:29..16:32): ??? -> scala/Predef.`???`().
23972397
[17:6..17:8): m7 <- example/Methods#m7().
23982398
[17:9..17:10): U <- example/Methods#m7().[U]
2399-
[17:10..17:10): <- example/Methods#m7().(evidence$1)
24002399
[17:12..17:20): Ordering -> scala/math/Ordering#
24012400
[17:20..17:20): -> example/Methods#m7().[U]
24022401
[17:22..17:23): c <- example/Methods#m7().(c)
@@ -3074,7 +3073,7 @@ Uri => Synthetic.scala
30743073
Text => empty
30753074
Language => Scala
30763075
Symbols => 40 entries
3077-
Occurrences => 164 entries
3076+
Occurrences => 163 entries
30783077

30793078
Symbols:
30803079
example/Synthetic# => class Synthetic extends Object { self: Synthetic => +21 decls }
@@ -3223,7 +3222,6 @@ Occurrences:
32233222
[32:8..32:9): J <- example/Synthetic#J#
32243223
[32:9..32:9): <- example/Synthetic#J#`<init>`().
32253224
[32:10..32:11): T <- example/Synthetic#J#[T]
3226-
[32:11..32:11): <- example/Synthetic#J#evidence$1.
32273225
[32:13..32:21): Manifest -> scala/Predef.Manifest#
32283226
[32:21..32:21): -> example/Synthetic#J#[T]
32293227
[32:29..32:32): arr <- example/Synthetic#J#arr.

0 commit comments

Comments
 (0)