Skip to content

Commit 7652a2f

Browse files
Merge pull request #5435 from poechsel/tasty-to-semanticdb
Addition to TASTy reflect to semantic DB
2 parents 052c3b1 + 4373c10 commit 7652a2f

38 files changed

+1259
-24
lines changed

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ val `dotty-language-server` = Build.`dotty-language-server`
1313
val `dotty-bench` = Build.`dotty-bench`
1414
val `dotty-bench-bootstrapped` = Build.`dotty-bench-bootstrapped`
1515
val `dotty-semanticdb` = Build.`dotty-semanticdb`
16+
val `dotty-semanticdb-input` = Build.`dotty-semanticdb-input`
1617
val `scala-library` = Build.`scala-library`
1718
val `scala-compiler` = Build.`scala-compiler`
1819
val `scala-reflect` = Build.`scala-reflect`

compiler/src/dotty/tools/dotc/tastyreflect/PositionOpsImpl.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ trait PositionOpsImpl extends scala.tasty.reflect.PositionOps with CoreImpl {
66
def start: Int = pos.start
77
def end: Int = pos.end
88

9+
def exists: Boolean = pos.exists
10+
911
def sourceFile: java.nio.file.Path = pos.source.file.jpath
1012

1113
def startLine: Int = pos.startLine
@@ -14,5 +16,4 @@ trait PositionOpsImpl extends scala.tasty.reflect.PositionOps with CoreImpl {
1416
def startColumn: Int = pos.startColumn
1517
def endColumn: Int = pos.endColumn
1618
}
17-
1819
}

compiler/src/dotty/tools/dotc/tastyreflect/SymbolOpsImpl.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ trait SymbolOpsImpl extends scala.tasty.reflect.SymbolOps with CoreImpl {
2626
def name(implicit ctx: Context): String = symbol.name.toString
2727
def fullName(implicit ctx: Context): String = symbol.fullName.toString
2828

29+
def pos(implicit ctx: Context): Position = symbol.pos
30+
2931
def owner(implicit ctx: Context): Symbol = symbol.owner
3032

3133
def localContext(implicit ctx: Context): Context = {

compiler/src/dotty/tools/dotc/tastyreflect/TypeOrBoundsTreesOpsImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
1818

1919
def TypeTreeDeco(tpt: TypeTree): TypeTreeAPI = new TypeTreeAPI {
2020
def pos(implicit ctx: Context): Position = tpt.pos
21-
def tpe(implicit ctx: Context): Type = tpt.tpe.stripTypeVar
2221
def symbol(implicit ctx: Context): Symbol = tpt.symbol
22+
def tpe(implicit ctx: Context): Type = tpt.tpe.stripTypeVar
2323
}
2424

2525
object IsTypeTree extends IsTypeTreeExtractor {

library/src/scala/tasty/reflect/PositionOps.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ trait PositionOps extends Core {
44

55
trait PositionAPI {
66

7-
/** The path of source file */
7+
def exists: Boolean
8+
89
def sourceFile: java.nio.file.Path
910

1011
/** The start index in the source file */

library/src/scala/tasty/reflect/SymbolOps.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ trait SymbolOps extends Core {
2626
/** The full name of this symbol up to the root package. */
2727
def fullName(implicit ctx: Context): String
2828

29-
/** Returns the context within this symbol. */
29+
def pos(implicit ctx: Context): Position
30+
3031
def localContext(implicit ctx: Context): Context
3132

3233
/** Unsafe cast as to PackageSymbol. Use IsPackageSymbol to safly check and cast to PackageSymbol */

library/src/scala/tasty/reflect/TreeUtils.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ trait TreeUtils
104104
case TypeTree.Block(typedefs, tpt) => foldTypeTree(foldTrees(x, typedefs), tpt)
105105
case TypeTree.MatchType(boundopt, selector, cases) =>
106106
foldTypeCaseDefs(foldTypeTree(boundopt.fold(x)(foldTypeTree(x, _)), selector), cases)
107+
case SyntheticBounds() => x
107108
case TypeBoundsTree(lo, hi) => foldTypeTree(foldTypeTree(x, lo), hi)
108109
}
109110

library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ trait TypeOrBoundsTreeOps extends Core {
2828
val TypeTree: TypeTreeModule
2929
abstract class TypeTreeModule extends TypeTreeCoreModule {
3030

31+
3132
/** TypeTree containing an inferred type */
3233
val Synthetic: SyntheticExtractor
3334
abstract class SyntheticExtractor {

project/Build.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ object Build {
393393
baseDirectory in Test := baseDirectory.value / "..",
394394
unmanagedSourceDirectories in Test += baseDirectory.value / "input" / "src" / "main" / "scala",
395395
libraryDependencies ++= List(
396-
("org.scalameta" %% "semanticdb" % "4.0.0" % Test).withDottyCompat(scalaVersion.value),
397-
"com.novocode" % "junit-interface" % "0.11" % Test,
398-
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0" % Test
396+
("org.scalameta" %% "semanticdb" % "4.0.0").withDottyCompat(scalaVersion.value),
397+
"com.novocode" % "junit-interface" % "0.11",
398+
"com.googlecode.java-diff-utils" % "diffutils" % "1.3.0"
399399
)
400400
)
401401

@@ -919,6 +919,11 @@ object Build {
919919
lazy val `dotty-bench-bootstrapped` = project.in(file("bench")).asDottyBench(Bootstrapped)
920920

921921
lazy val `dotty-semanticdb` = project.in(file("semanticdb")).asDottySemanticdb(Bootstrapped)
922+
lazy val `dotty-semanticdb-input` = project.in(file("semanticdb/input")).settings(
923+
scalaVersion := "2.12.7",
924+
scalacOptions += "-Yrangepos",
925+
addCompilerPlugin("org.scalameta" % "semanticdb-scalac" % "4.0.0" cross CrossVersion.full)
926+
)
922927

923928
// Depend on dotty-library so that sbt projects using dotty automatically
924929
// depend on the dotty-library
@@ -1317,6 +1322,7 @@ object Build {
13171322
enablePlugins(JmhPlugin)
13181323

13191324
def asDottySemanticdb(implicit mode: Mode): Project = project.withCommonSettings.
1325+
aggregate(`dotty-semanticdb-input`).
13201326
dependsOn(dottyCompiler).
13211327
settings(semanticdbSettings)
13221328

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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package example
2+
3+
import scala.language.existentials
4+
import scala.language.higherKinds
5+
import scala.language.reflectiveCalls
6+
7+
class AdvC[T] {
8+
def t: T = ???
9+
}
10+
11+
class Structural {
12+
def s1: { val x: Int } = ???
13+
def s2 = new { val x: Int = ??? }
14+
def s3 = new { def m(x: Int): Int = ??? }
15+
}
16+
17+
class Existential {
18+
def e1: List[_] = ???
19+
}
20+
21+
class AdvD[CC[B]] extends AdvC[CC[B]]
22+
23+
object AdvTest {
24+
val s = new Structural
25+
val s1 = s.s1
26+
val s2 = s.s2
27+
val s3 = s.s3
28+
29+
val e = new Existential
30+
val e1 = e.e1
31+
val e1x = e.e1.head
32+
locally {
33+
(??? : Any) match {
34+
case e3: List[_] =>
35+
val e3x = e3.head
36+
()
37+
}
38+
}
39+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package example
2+
import scala.language.higherKinds
3+
4+
class Anonymous {
5+
this: Anonymous =>
6+
7+
def m1[T[_], B] = ???
8+
def m2: Map[_, List[_]] = ???
9+
locally {
10+
??? match { case _: List[_] => }
11+
}
12+
locally {
13+
val x: Int => Int = _ => ???
14+
}
15+
16+
trait Foo
17+
var x = new Foo {}
18+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package example
2+
3+
class C1(val x1: Int) extends AnyVal
4+
5+
class C2(val x2: Int) extends AnyVal
6+
object C2
7+
8+
case class C3(x: Int)
9+
10+
case class C4(x: Int)
11+
object C4
12+
13+
object M {
14+
implicit class C5(x: Int)
15+
}
16+
17+
case class C6(private val x: Int)
18+
19+
class C7(x: Int)
20+
21+
class C8(private[this] val x: Int)
22+
23+
class C9(private[this] var x: Int)
24+
25+
object N {
26+
val anonClass = new C7(42) {
27+
val local = ???
28+
}
29+
val anonFun = List(1).map { i =>
30+
val local = 2
31+
local + 2
32+
}
33+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package example
2+
3+
class AdvA {
4+
def b: AdvB = ???
5+
}
6+
7+
class AdvB {
8+
def a: AdvA = ???
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package example
2+
3+
object EmptyObject {}

semanticdb/input/src/main/scala/example/Example.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ class Example {
1515
y
1616
)
1717
}
18+
19+
class ExampleInit() {
20+
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package example
2+
3+
import scala.concurrent.Future
4+
5+
object OExample { self =>
6+
def main(args: Array[String]): Unit = {
7+
println(1)
8+
}
9+
val x = scala.reflect.classTag[Int]
10+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package example
2+
3+
// This class should be excluded by semanticdb.
4+
class Exclude
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package example
2+
3+
package object p {
4+
private lazy val x = 1
5+
protected implicit var y: Int = 2
6+
def z(pp: Int) = 3
7+
def m[TT] = ???
8+
abstract class C[+T, -U, V](x: T, y: U, z: V) {
9+
def this() = this(???, ???, ???)
10+
def w: Int
11+
}
12+
type T1 = Int
13+
type T2[T] = S[T]
14+
type U <: Int
15+
type V >: Int
16+
case object X
17+
final class Y
18+
sealed trait Z
19+
class AA(x: Int, val y: Int, var z: Int)
20+
class S[@specialized T]
21+
val List(xs1) = ???
22+
??? match { case List(xs2) => ??? }
23+
??? match { case _: List[t] => ??? }
24+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//import scala.util.control.NonFatal
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// See https://github.com/scalameta/scalameta/issues/1749
2+
package example
3+
4+
import scala.math.Ordered.orderingToOrdered
5+
6+
class Issue1749 {
7+
val x1 = 42
8+
val x2 = 42
9+
(x1, x1)
10+
.compare((x2, x2))
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package example
2+
3+
object Test {
4+
val xs = {
5+
val x = 42
6+
List(x)
7+
}
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package example
2+
3+
//@MacroAnnotation
4+
class MacroAnnotations
5+
object MacroAnnotations
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package example
2+
3+
class MethodUsages {
4+
val m = new Methods[Int]
5+
m.m1
6+
m.m2()
7+
m.m3(0)
8+
m.m4(0)(0)
9+
m.m5("")
10+
m.m5(0)
11+
m.m6(0)
12+
m.m6(new m.List[Int])
13+
m.m6(Nil)
14+
m.m7a(m, new m.List[Int])
15+
m.m7b(new m.List[Int])
16+
m.`m8().`()
17+
m.m9(null)
18+
m.m10(null)
19+
m.m11(Predef)
20+
m.m11(OExample)
21+
m.m12a(null)
22+
m.m12b(null)
23+
m.m13(0)
24+
m.m15(0)
25+
m.m16(0)
26+
m.m16(0)
27+
m.m17.m()
28+
m.m17(1)
29+
m.m17("")
30+
m.m18.m()
31+
m.m18(1)
32+
m.m18("")
33+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package example
2+
3+
import scala.math.Ordering
4+
import scala.language.existentials
5+
6+
class Methods[T] {
7+
class List[T]
8+
type AList[T] = List[T]
9+
def m1 = ???
10+
def m2() = ???
11+
def m3(x: Int) = ???
12+
def m4(x: Int)(y: Int) = ???
13+
def m5(x: String) = ???
14+
def m5(x: Int) = ???
15+
def m6(x: Int) = ???
16+
def m6(x: List[T]) = ???
17+
def m6(x: scala.List[T]) = ???
18+
def m7a[U: Ordering](c: Methods[T], l: List[U]) = ???
19+
def m7b[U <: T](l: List[U]) = ???
20+
def `m8().`() = ???
21+
class `m9().`
22+
def m9(x: `m9().`) = ???
23+
def m10(x: AList[T]) = ???
24+
def m11(x: Predef.type) = ???
25+
def m11(x: OExample.type) = ???
26+
def m12a(x: {}) = ???
27+
def m12b(x: { val x: Int }) = ???
28+
def m13(x: Int @unchecked) = ???
29+
def m15(x: => Int) = ???
30+
def m16(x: Int*) = ???
31+
object m17 { def m() = ??? }
32+
def m17(a: Int) = ???
33+
def m17(b: String) = ???
34+
val m18 = m17
35+
def m18(a: Int) = ???
36+
def m18(b: String) = ???
37+
def m19(x: Int, y: Int = 2)(z: Int = 3) = ???
38+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package example
2+
3+
object X {
4+
object Y
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package example
2+
3+
trait OveA { def foo: Int }
4+
class OveB() extends OveA { def foo: Int = 2 }

0 commit comments

Comments
 (0)