Skip to content

Commit 2c40921

Browse files
committed
fix overload order and indexing, remove references at package defs
1 parent 29492ff commit 2c40921

File tree

13 files changed

+135
-72
lines changed

13 files changed

+135
-72
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ class ExtractSemanticDB extends Phase {
7979
if !owner.isRoot && !owner.isEmptyPackage then addSymName(b, owner)
8080

8181
def addOverloadIdx(sym: Symbol): Unit =
82-
val alts = sym.owner.info.decls.lookupAll(sym.name).toList
82+
val alts = sym.owner.info.decls.lookupAll(sym.name).toList.reverse
8383
if alts.tail.nonEmpty then
8484
val idx = alts.indexOf(sym)
8585
assert(idx >= 0)
86-
b.append('+').append(idx)
86+
if idx > 0 then
87+
b.append('+').append(idx)
8788

8889
def addDescriptor(sym: Symbol): Unit =
8990
if sym.is(ModuleClass) then
@@ -186,6 +187,7 @@ class ExtractSemanticDB extends Phase {
186187
registerUse(alt.symbol, sel.imported.span)
187188
case tree: Inlined =>
188189
traverse(tree.call)
190+
case tree: PackageDef => tree.stats.foreach(traverse)
189191
case _ =>
190192
traverseChildren(tree)
191193
}

compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import dotty.tools.dotc.semanticdb.DiffAssertions._
2121
class SemanticdbTests {
2222
val scalaFile = FileSystems.getDefault.getPathMatcher("glob:**.scala")
2323
val expectFile = FileSystems.getDefault.getPathMatcher("glob:**.expect.scala")
24-
val semanticdbFile = FileSystems.getDefault.getPathMatcher("glob:**.scala.semanticdb")
24+
// val semanticdbFile = FileSystems.getDefault.getPathMatcher("glob:**.scala.semanticdb")
2525
val src = Paths.get(System.getProperty("user.dir")).resolve("tests").resolve("semanticdb")
2626

2727
@Category(Array(classOf[dotty.SlowTests]))
@@ -64,6 +64,7 @@ class SemanticdbTests {
6464
val args = Array(
6565
"-Ysemanticdb",
6666
"-d", target.toString,
67+
// "-Xprint:extractSemanticDB",
6768
"-sourceroot", src.toString,
6869
"-usejavacp",
6970
) ++ inputFiles().map(_.toString)

compiler/test/dotty/tools/dotc/semanticdb/Semanticdbs.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ object Semanticdbs {
6767
sourceFile.lineToOffset(range.endLine) + range.endCharacter
6868
)
6969
sb.append(doc.text.substring(offset, end))
70-
.append(" /* ")
71-
.append(if (occ.role.isDefinition) "<<< " else "ref ")
70+
.append(" /*")
71+
.append(if (occ.role.isDefinition) "<<=" else "=>>")
7272
.append(occ.symbol.replace('/', '.'))
73-
.append(" */ ")
73+
.append("*/ ")
7474
offset = end
7575
}
7676
sb.append(doc.text.substring(offset))

tests/semanticdb/Access.expect.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package example
2+
3+
class /*=>>java.lang.Object#`<init>`().*/ Access /*<<=example.Access#*/ {
4+
private def m1 /*<<=example.Access#m1().*/ = ??? /*=>>scala.Predef.`???`().*/
5+
private[this] def m2 /*<<=example.Access#m2().*/ = ??? /*=>>scala.Predef.`???`().*/
6+
private[Access] def m3 /*<<=example.Access#m3().*/ = ??? /*=>>scala.Predef.`???`().*/
7+
protected def m4 /*<<=example.Access#m4().*/ = ??? /*=>>scala.Predef.`???`().*/
8+
protected[this] def m5 /*<<=example.Access#m5().*/ = ??? /*=>>scala.Predef.`???`().*/
9+
protected[example] def m6 /*<<=example.Access#m6().*/ = ??? /*=>>scala.Predef.`???`().*/
10+
def m7 /*<<=example.Access#m7().*/ = ??? /*=>>scala.Predef.`???`().*/
11+
}

tests/semanticdb/Access.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package example
2+
3+
class Access {
4+
private def m1 = ???
5+
private[this] def m2 = ???
6+
private[Access] def m3 = ???
7+
protected def m4 = ???
8+
protected[this] def m5 = ???
9+
protected[example] def m6 = ???
10+
def m7 = ???
11+
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package a /* ref a. */
2-
object /* ref java.lang.Object#`<init>`(). */ Definitions /* <<< a.Definitions. */ {
3-
/* ref scala.package.Serializable# */ /* ref scala. */ /* ref _root_ */ /* ref a.Definitions. */ val a /* <<< a.Definitions.a. */ = 1
4-
var b /* <<< a.Definitions.b. */ = /* <<< a.Definitions.`b_=`(). */ 2
5-
def c /* <<< a.Definitions.c(). */ = 3
6-
class /* ref java.lang.Object#`<init>`(). */ D /* <<< a.Definitions.D# */
7-
trait E /* <<< a.Definitions.E# */
1+
package a
2+
object /*=>>java.lang.Object#`<init>`().*/ Definitions /*<<=a.Definitions.*/ {
3+
/*=>>scala.package.Serializable#*/ /*=>>scala.*/ /*=>>_root_*/ /*=>>a.Definitions.*/ val a /*<<=a.Definitions.a.*/ = 1
4+
var b /*<<=a.Definitions.b.*/ = /*<<=a.Definitions.`b_=`().*/ 2
5+
def c /*<<=a.Definitions.c().*/ = 3
6+
class /*=>>java.lang.Object#`<init>`().*/ D /*<<=a.Definitions.D#*/
7+
trait E /*<<=a.Definitions.E#*/
88
}

tests/semanticdb/Enums.expect.scala

Lines changed: 34 additions & 34 deletions
Large diffs are not rendered by default.

tests/semanticdb/Givens.expect.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package a
2+
package b
3+
4+
object /*=>>java.lang.Object#`<init>`().*/ Givens /*<<=a.b.Givens.*/
5+
6+
/*=>>scala.package.Serializable#*/ /*=>>scala.*/ /*=>>_root_*/ /*=>>a.b.Givens.*/ given /*=>>java.lang.Object#`<init>`().*/ :[A](any: A)
7+
de /*<<=a.b.Givens.given_sayHello_of_A.*/ /*=>>a.b.Givens.given_sayHello_of_A.*/ /*<<=a.b.Givens.given_sayHello_of_A.sayHello().(A)*/ /*<<=a.b.Givens.given_sayHello_of_A.sayHello().(any)*/ /*=>>a.b.Givens.given_sayHello_of_A.sayHello().(A)*/ /*=>>scala.package.Serializable#*/ /*=>>scala.*/ /*=>>_root_*/ f sayHello /*<<=a.b.Givens.given_sayHello_of_A.sayHello().*/ = s" /*=>>scala.StringContext.*/ /*=>>scala.*/ /*=>>_root_*/ Hello, I am $any /*=>>a.b.Givens.given_sayHello_of_A.sayHello().(any)*/ /*=>>scala.StringContext#s().*/ "
8+
9+
val hello1 /*<<=a.b.Givens.hello1.*/ = /*=>>a.b.Givens.given_sayHello_of_A.sayHello().*/ /*=>>a.b.Givens.given_sayHello_of_A.*/ 1.sayHello
10+
11+
trait Monoid /*<<=a.b.Givens.Monoid#*/ [A]
12+
/*<<=a.b.Givens.Monoid#`<init>`().*/ /*<<=a.b.Givens.Monoid#`<init>`().(A)*/ /*<<=a.b.Givens.Monoid#(A)*/ def empty /*<<=a.b.Givens.Monoid#empty().*/ : A /*=>>a.b.Givens.Monoid#(A)*/
13+
def (x: A) /*<<=a.b.Givens.Monoid#combine().*/ /*<<=a.b.Givens.Monoid#combine().(x)*/ /*=>>a.b.Givens.Monoid#(A)*/ combine (y /*<<=a.b.Givens.Monoid#combine().(y)*/ : A /*=>>a.b.Givens.Monoid#(A)*/ ): A /*=>>a.b.Givens.Monoid#(A)*/
14+
15+
given /*=>>java.lang.Object#`<init>`().*/ /*=>>a.b.Givens.given_Monoid_String.*/ Monoid /*=>>a.b.Givens.Monoid#*/ [String]
16+
/*<<=a.b.Givens.given_Monoid_String.*/ /*=>>scala.Predef.String#*/ /*=>>scala.package.Serializable#*/ /*=>>scala.*/ /*=>>_root_*/ def empty /*<<=a.b.Givens.given_Monoid_String.empty().*/ = ""
17+
def (x: Str /*<<=a.b.Givens.given_Monoid_String.combine().*/ /*<<=a.b.Givens.given_Monoid_String.combine().(x)*/ ing /*=>>scala.Predef.String#*/ ) combine (y /*<<=a.b.Givens.given_Monoid_String.combine().(y)*/ : String /*=>>scala.Predef.String#*/ ) = x /*=>>a.b.Givens.given_Monoid_String.combine().(x)*/ + /*=>>java.lang.String#`+`().*/ y /*=>>a.b.Givens.given_Monoid_String.combine().(y)*/
18+
19+
inline given int2String /*<<=a.b.Givens.int2String().*/ : Conversion /*=>>scala.Conversion#*/ [Int /*=>>scala.Int#*/ , String /*=>>scala.Predef.String#*/ ] = _ /*=>>local0*/ .toString /*=>>scala.Any#toString().*/
20+
21+
def foo /*<<=a.b.Givens.foo().*/ [A /*<<=a.b.Givens.foo().(A)*/ ](given A /*<<=a.b.Givens.foo().(A)*/ : Monoid /*=>>a.b.Givens.Monoid#*/ [A /*=>>a.b.Givens.foo().(A)*/ ]): A /*=>>a.b.Givens.foo().(A)*/ = A /*=>>a.b.Givens.foo().(A)*/ .combine /*=>>a.b.Givens.Monoid#combine().*/ (A /*=>>a.b.Givens.foo().(A)*/ .empty /*=>>a.b.Givens.Monoid#empty().*/ )(A /*=>>a.b.Givens.foo().(A)*/ .empty /*=>>a.b.Givens.Monoid#empty().*/ )

tests/semanticdb/Givens.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package a
2+
package b
3+
4+
object Givens
5+
6+
given :[A](any: A)
7+
def sayHello = s"Hello, I am $any"
8+
9+
val hello1 = 1.sayHello
10+
11+
trait Monoid[A]
12+
def empty: A
13+
def (x: A) combine (y: A): A
14+
15+
given Monoid[String]
16+
def empty = ""
17+
def (x: String) combine (y: String) = x + y
18+
19+
inline given int2String: Conversion[Int, String] = _.toString
20+
21+
def foo[A](given A: Monoid[A]): A = A.combine(A.empty)(A.empty)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* ref _empty_ */ object /* ref java.lang.Object#`<init>`(). */ NewModifiers /* <<< NewModifiers. */ {
2-
/* ref scala.package.Serializable# */ /* ref scala. */ /* ref _root_ */ /* ref NewModifiers. */ inline val foo /* <<< NewModifiers.foo. */ = "foo"
3-
opaque type A /* <<< NewModifiers.A# */ = Int /* ref scala.Int# */
1+
object /*=>>java.lang.Object#`<init>`().*/ NewModifiers /*<<=NewModifiers.*/ {
2+
/*=>>scala.package.Serializable#*/ /*=>>scala.*/ /*=>>_root_*/ /*=>>NewModifiers.*/ inline val foo /*<<=NewModifiers.foo.*/ = "foo"
3+
opaque type A /*<<=NewModifiers.A#*/ = Int /*=>>scala.Int#*/
44
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
/* ref _empty_ */ object /* ref java.lang.Object#`<init>`(). */ A /* <<< A. */ {
1+
object /*=>>java.lang.Object#`<init>`().*/ A /*<<=A.*/ {
22

3-
/* ref scala.package.Serializable# */ /* ref scala. */ /* ref _root_ */ /* ref A. */ def foo /* <<< A.foo(+1). */ (x /* <<< A.foo(+1).(x) */ : Int /* ref scala.Int# */ ) = ()
4-
def foo /* <<< A.foo(+0). */ (): Unit /* ref scala.Unit# */ = ()
3+
/*=>>scala.package.Serializable#*/ /*=>>scala.*/ /*=>>_root_*/ /*=>>A.*/ def foo /*<<=A.foo().*/ (x /*<<=A.foo().(x)*/ : Int /*=>>scala.Int#*/ ) = ()
4+
def foo /*<<=A.foo(+1).*/ (): Unit /*=>>scala.Unit#*/ = ()
55

6-
foo /* ref A.foo(+1). */ (1)
7-
foo /* ref A.foo(+0). */ ()
6+
foo /*=>>A.foo().*/ (1)
7+
foo /*=>>A.foo(+1).*/ ()
88

9-
"".substring /* ref java.lang.String#substring(+1). */ (1)
10-
"".substring /* ref java.lang.String#substring(+0). */ (1, 2)
9+
"".substring /*=>>java.lang.String#substring().*/ (1)
10+
"".substring /*=>>java.lang.String#substring(+1).*/ (1, 2)
1111

12-
List /* ref scala.package.List. */ /* ref scala.collection.IterableFactory#apply(). */ (1, 2)
13-
List /* ref scala.package.List. */ .apply /* ref scala.collection.IterableFactory#apply(). */ ()
14-
List /* ref scala.package.List. */ .`apply` /* ref scala.collection.IterableFactory#apply(). */ ()
15-
println /* ref scala.Predef.println(+0). */ (1 + /* ref scala.Int#`+`(+3). */ 2)
12+
List /*=>>scala.package.List.*/ /*=>>scala.collection.IterableFactory#apply().*/ (1, 2)
13+
List /*=>>scala.package.List.*/ .apply /*=>>scala.collection.IterableFactory#apply().*/ ()
14+
List /*=>>scala.package.List.*/ .`apply` /*=>>scala.collection.IterableFactory#apply().*/ ()
15+
println /*=>>scala.Predef.println(+1).*/ (1 + /*=>>scala.Int#`+`(+4).*/ 2)
1616

17-
/* ref A.Foo#`<init>`(). */ /* ref A.Foo#copy().(x) */ /* ref A.Foo.apply().(x) */ case class /* ref java.lang.Object#`<init>`(). */ Foo /* <<< A.Foo# */ (x: In /* <<< A.Foo#`<init>`(). */ /* <<< A.Foo#`<init>`().(x) */ /* <<< A.Foo#(x) */ /* <<< A.Foo#copy().(x) */ /* <<< A.Foo.apply().(x) */ t /* ref scala.Int# */ /* ref A.Foo#(x) */ /* ref scala.package.Serializable# */ /* ref scala. */ /* ref _root_ */ ) /* ref scala.Product# */ /* ref scala. */ /* ref _root_ */ /* ref scala.package.Serializable# */
17+
/*=>>A.Foo#`<init>`().*/ /*=>>A.Foo#copy().(x)*/ /*=>>A.Foo.apply().(x)*/ case class /*=>>java.lang.Object#`<init>`().*/ Foo /*<<=A.Foo#*/ (x: In /*<<=A.Foo#`<init>`().*/ /*<<=A.Foo#`<init>`().(x)*/ /*<<=A.Foo#(x)*/ /*<<=A.Foo#copy().(x)*/ /*<<=A.Foo.apply().(x)*/ t /*=>>scala.Int#*/ /*=>>A.Foo#(x)*/ /*=>>scala.package.Serializable#*/ /*=>>scala.*/ /*=>>_root_*/ ) /*=>>scala.Product#*/ /*=>>scala.*/ /*=>>_root_*/ /*=>>scala.package.Serializable#*/
1818
}
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/* ref _empty_ */ /* ref java.lang.Object#`<init>`(). */ /* ref scala.package.Serializable# */ /* ref scala. */ /* ref _root_ */ /* ref toplevel$package. */ inline val a = " /* <<< toplevel$package. */ /* <<< toplevel$package.a. */ "
2-
def (x: Int /* <<< toplevel$package.combine(). */ /* <<< toplevel$package.combine().(x) */ /* ref scala.Int# */ ) combine (y /* <<< toplevel$package.combine().(y) */ : Int /* ref scala.Int# */ ) = x /* ref toplevel$package.combine().(x) */ + /* ref scala.Int#`+`(+3). */ y /* ref toplevel$package.combine().(y) */
3-
given /* ref java.lang.Object#`<init>`(). */ [A](any: A) {
4-
def /* <<< toplevel$package.given_sayHello_of_A. */ /* ref toplevel$package.given_sayHello_of_A. */ /* <<< toplevel$package.given_sayHello_of_A.sayHello().(A) */ /* <<< toplevel$package.given_sayHello_of_A.sayHello().(any) */ /* ref toplevel$package.given_sayHello_of_A.sayHello().(A) */ /* ref scala.package.Serializable# */ /* ref scala. */ /* ref _root_ */ sayHello /* <<< toplevel$package.given_sayHello_of_A.sayHello(). */ = s" /* ref scala.StringContext. */ /* ref scala. */ /* ref _root_ */ Hello, I am $any /* ref toplevel$package.given_sayHello_of_A.sayHello().(any) */ /* ref scala.StringContext#s(+1). */ "
5-
}
6-
val hello1 /* <<< toplevel$package.hello1. */ = /* ref toplevel$package.given_sayHello_of_A.sayHello(). */ /* ref toplevel$package.given_sayHello_of_A. */ 1.sayHello
1+
/*=>>java.lang.Object#`<init>`().*/ /*=>>scala.package.Serializable#*/ /*=>>scala.*/ /*=>>_root_*/ /*=>>toplevel$package.*/ inline val a = " /*<<=toplevel$package.*/ /*<<=toplevel$package.a.*/ "
2+
def (x: Int /*<<=toplevel$package.combine().*/ /*<<=toplevel$package.combine().(x)*/ /*=>>scala.Int#*/ ) combine (y /*<<=toplevel$package.combine().(y)*/ : Int /*=>>scala.Int#*/ ) = x /*=>>toplevel$package.combine().(x)*/ + /*=>>scala.Int#`+`(+4).*/ y /*=>>toplevel$package.combine().(y)*/
3+
def combine /*<<=toplevel$package.combine(+1).*/ (x /*<<=toplevel$package.combine(+1).(x)*/ : Int /*=>>scala.Int#*/ , y /*<<=toplevel$package.combine(+1).(y)*/ : Int /*=>>scala.Int#*/ , z /*<<=toplevel$package.combine(+1).(z)*/ : Int /*=>>scala.Int#*/ ) = x /*=>>toplevel$package.combine(+1).(x)*/ + /*=>>scala.Int#`+`(+4).*/ y /*=>>toplevel$package.combine(+1).(y)*/ + /*=>>scala.Int#`+`(+4).*/ z /*=>>toplevel$package.combine(+1).(z)*/
4+
def combine /*<<=toplevel$package.combine(+2).*/ = 0

tests/semanticdb/toplevel.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
inline val a = ""
22
def (x: Int) combine (y: Int) = x + y
3-
given [A](any: A) {
4-
def sayHello = s"Hello, I am $any"
5-
}
6-
val hello1 = 1.sayHello
3+
def combine(x: Int, y: Int, z: Int) = x + y + z
4+
def combine = 0

0 commit comments

Comments
 (0)