Skip to content

Commit 1c67d79

Browse files
committed
fix literal type in ctor, move tests
1 parent 51ce9bb commit 1c67d79

File tree

12 files changed

+431
-272
lines changed

12 files changed

+431
-272
lines changed

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ class ExtractSemanticDB extends Phase:
7272
/** The symbol occurrences generated so far, as a set */
7373
private val generated = new mutable.HashSet[SymbolOccurrence]
7474

75-
private val anotatedSymbols = new mutable.HashSet[Symbol]
76-
7775
/** Definitions of this symbol should be excluded from semanticdb */
7876
private def excludeDef(sym: Symbol)(using Context): Boolean =
7977
!sym.exists
@@ -107,28 +105,15 @@ class ExtractSemanticDB extends Phase:
107105
|| qualifier.exists(excludeQual)
108106

109107
private def traverseAnnotsOfDefinition(sym: Symbol)(using Context): Unit =
110-
if (!anotatedSymbols.contains(sym)) then
111-
anotatedSymbols += sym
112-
for annot <- sym.annotations do
113-
if annot.tree.span.exists
114-
&& annot.tree.span.hasLength
115-
annot.tree match
116-
case tree: Typed => () // hack for inline code
117-
case tree => traverse(tree)
108+
for annot <- sym.annotations do
109+
if annot.tree.span.exists
110+
&& annot.tree.span.hasLength
111+
annot.tree match
112+
case tree: Typed => () // hack for inline code
113+
case tree => traverse(tree)
118114

119115
override def traverse(tree: Tree)(using Context): Unit =
120116

121-
def traverseCtorParamTpt(ctorSym: Symbol, tpt: Tree)(using Context): Unit =
122-
val tptSym = tpt match
123-
case ByNameTypeTree(tpt) => tpt.symbol
124-
case tpt => tpt.symbol
125-
if tptSym.owner == ctorSym
126-
val found = matchingMemberType(tptSym, ctorSym.owner)
127-
if tpt.span.hasLength
128-
registerUseGuarded(None, found, tpt.span)
129-
else
130-
traverse(tpt)
131-
132117
tree match
133118
case tree: DefTree if tree.symbol.exists =>
134119
traverseAnnotsOfDefinition(tree.symbol)
@@ -192,7 +177,7 @@ class ExtractSemanticDB extends Phase:
192177
if !excludeDef(ctorSym)
193178
traverseAnnotsOfDefinition(ctorSym)
194179
registerDefinition(ctorSym, tree.constr.span, Set.empty)
195-
ctorParams(tree.constr.vparamss, tree.body)(traverseCtorParamTpt(ctorSym, _))
180+
ctorParams(tree.constr.vparamss, tree.body)
196181
for parent <- tree.parentsOrDerived if parent.span.hasLength do
197182
traverse(parent)
198183
val selfSpan = tree.self.span
@@ -571,7 +556,7 @@ class ExtractSemanticDB extends Phase:
571556
symkinds.toSet
572557

573558
private def ctorParams(
574-
vparamss: List[List[ValDef]], body: List[Tree])(traverseTpt: Tree => Unit)(using Context): Unit =
559+
vparamss: List[List[ValDef]], body: List[Tree])(using Context): Unit =
575560
@tu lazy val getters = findGetters(vparamss.flatMap(_.map(_.name)).toSet, body)
576561
for
577562
vparams <- vparamss
@@ -583,7 +568,7 @@ class ExtractSemanticDB extends Phase:
583568
getters.get(vparam.name).fold(SymbolKind.emptySet)(getter =>
584569
if getter.mods.is(Mutable) then SymbolKind.VarSet else SymbolKind.ValSet)
585570
registerSymbol(vparam.symbol, symbolName(vparam.symbol), symkinds)
586-
traverseTpt(vparam.tpt)
571+
traverse(vparam.tpt)
587572

588573
object ExtractSemanticDB:
589574
import java.nio.file.Path

tests/pos-custom-args/semanticdb/ctorByName.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/pos-custom-args/semanticdb/recursiveAnnotResolve.scala

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/semanticdb/expect/Classes.expect.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class C8/*<-classes::C8#*/(private[this] val x/*<-classes::C8#x.*/: Int/*->scala
2222

2323
class C9/*<-classes::C9#*/(private[this] var x/*<-classes::C9#x().*/: Int/*->scala::Int#*/)
2424

25+
class C10/*<-classes::C10#*/(s/*<-classes::C10#s.*/: => String/*->scala::Predef.String#*/)
26+
2527
object N/*<-classes::N.*/ {
2628
val anonClass/*<-classes::N.anonClass.*/ = new C7/*->classes::C7#*/(42) {
2729
val local/*<-local1*/ = ???/*->scala::Predef.`???`().*/

tests/semanticdb/expect/Classes.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class C8(private[this] val x: Int)
2222

2323
class C9(private[this] var x: Int)
2424

25+
class C10(s: => String)
26+
2527
object N {
2628
val anonClass = new C7(42) {
2729
val local = ???

tests/semanticdb/expect/Enums.expect.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ object Enums/*<-_empty_::Enums.*/:
1616
suit/*->_empty_::Enums.Suits.isRed().(suit)*/ ==/*->scala::Any#`==`().*/ Hearts/*->_empty_::Enums.Suits.Hearts.*/ ||/*->scala::Boolean#`||`().*/ suit/*->_empty_::Enums.Suits.isRed().(suit)*/ ==/*->scala::Any#`==`().*/ Diamonds/*->_empty_::Enums.Suits.Diamonds.*/
1717

1818
def (suit: /*<-_empty_::Enums.Suits.isBlack().*//*<-_empty_::Enums.Suits.isBlack().(suit)*/Suits/*->_empty_::Enums.Suits#*/).isBlack: Boolean/*->scala::Boolean#*/ = suit/*->_empty_::Enums.Suits.isBlack().(suit)*/ match
19-
case Spades/*->_empty_::Enums.Suits.Spades.*/ | Diamonds/*->_empty_::Enums.Suits.Diamonds.*/ => true
20-
case _ => false
19+
case Spades/*->_empty_::Enums.Suits.Spades.*/ | Clubs/*->_empty_::Enums.Suits.Clubs.*/ => true
20+
case _ => false
2121

2222
enum WeekDays/*<-_empty_::Enums.WeekDays#*/:
2323
case Monday/*<-_empty_::Enums.WeekDays.Monday.*/

tests/semanticdb/expect/Enums.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ object Enums:
1616
suit == Hearts || suit == Diamonds
1717

1818
def (suit: Suits).isBlack: Boolean = suit match
19-
case Spades | Diamonds => true
20-
case _ => false
19+
case Spades | Clubs => true
20+
case _ => false
2121

2222
enum WeekDays:
2323
case Monday
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// semanticdb traversal of annotations of Nat caused an infinite loop
2+
package recursion
3+
4+
object Nats/*<-recursion::Nats.*/ {
5+
sealed trait Nat/*<-recursion::Nats.Nat#*/ {
6+
inline def ++/*<-recursion::Nats.Nat#`++`().*/ : Succ/*->recursion::Nats.Succ#*/[this.type] = Succ/*->recursion::Nats.Succ.*//*->recursion::Nats.Succ.apply().*/(this)
7+
8+
transparent inline def +/*<-recursion::Nats.Nat#`+`().*/(inline that/*<-recursion::Nats.Nat#`+`().(that)*/: Nat/*->recursion::Nats.Nat#*/): Nat/*->recursion::Nats.Nat#*/ =
9+
inline this match {
10+
case Zero/*->recursion::Nats.Zero.*/ => that/*->recursion::Nats.Nat#`+`().(that)*/
11+
case Succ/*->recursion::Nats.Succ.*//*->recursion::Nats.Succ.unapply().*//*->local0*/(p/*<-local1*/) => p/*->local1*/ +/*->recursion::Nats.Nat#`+`().*/ that/*->recursion::Nats.Nat#`+`().(that)*/.++/*->recursion::Nats.Nat#`++`().*/
12+
}
13+
}
14+
15+
case object Zero/*<-recursion::Nats.Zero.*/ extends Nat/*->recursion::Nats.Nat#*/
16+
case class Succ/*<-recursion::Nats.Succ#*/[N/*<-recursion::Nats.Succ#[N]*/ <: Nat](p/*<-recursion::Nats.Succ#p.*/: N/*->recursion::Nats.Succ#[N]*/) extends Nat/*->recursion::Nats.Nat#*/
17+
18+
transparent inline def toIntg/*<-recursion::Nats.toIntg().*/(inline n/*<-recursion::Nats.toIntg().(n)*/: Nat/*->recursion::Nats.Nat#*/): Int/*->scala::Int#*/ =
19+
inline n/*->recursion::Nats.toIntg().(n)*/ match {
20+
case Zero/*->recursion::Nats.Zero.*/ => 0
21+
case Succ/*->recursion::Nats.Succ.*//*->recursion::Nats.Succ.unapply().*//*->local2*/(p/*<-local3*/) => toIntg/*->recursion::Nats.toIntg().*/(p/*->local3*/) +/*->scala::Int#`+`(+4).*/ 1
22+
}
23+
24+
val j31/*<-recursion::Nats.j31.*/ = toIntg/*->recursion::Nats.toIntg().*/(Zero/*->recursion::Nats.Zero.*/.++.++.++/*<-local4*//*->recursion::Nats.Zero.*//*->recursion::Nats.Nat#`++`().*/ + /*<-local5*//*->recursion::Nats.Nat#`++`().*/Zer/*<-local6*//*->recursion::Nats.Nat#`++`().*//*->recursion::Nats.Nat#`+`().*/o/*->recursion::Nats.Zero.*/.++/*->recursion::Nats.Nat#`++`().*/)
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// semanticdb traversal of annotations of Nat caused an infinite loop
2+
package recursion
3+
4+
object Nats {
5+
sealed trait Nat {
6+
inline def ++ : Succ[this.type] = Succ(this)
7+
8+
transparent inline def +(inline that: Nat): Nat =
9+
inline this match {
10+
case Zero => that
11+
case Succ(p) => p + that.++
12+
}
13+
}
14+
15+
case object Zero extends Nat
16+
case class Succ[N <: Nat](p: N) extends Nat
17+
18+
transparent inline def toIntg(inline n: Nat): Int =
19+
inline n match {
20+
case Zero => 0
21+
case Succ(p) => toIntg(p) + 1
22+
}
23+
24+
val j31 = toIntg(Zero.++.++.++ + Zero.++)
25+
}

tests/semanticdb/expect/semanticdb-Types.expect.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class T/*<-types::T#*/ {
2323
val x/*<-types::T#x.*/ = new X/*->types::T#X#*/
2424
}
2525

26+
case class Foo/*<-types::Foo#*/(s/*<-types::Foo#s.*/: "abc")
27+
28+
object Foo/*<-types::Foo.*/ {
29+
val x/*<-types::Foo.x.*/: "abc" @deprecated/*->scala::deprecated#*/ = "abc"
30+
val y/*<-types::Foo.y.*/: "abc" = x/*->types::Foo.x.*/
31+
}
32+
2633
object Test/*<-types::Test.*/ {
2734
class M/*<-types::Test.M#*/ {
2835
def m/*<-types::Test.M#m().*/: Int/*->scala::Int#*/ = ???/*->scala::Predef.`???`().*/

tests/semanticdb/expect/semanticdb-Types.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ class T {
2323
val x = new X
2424
}
2525

26+
case class Foo(s: "abc")
27+
28+
object Foo {
29+
val x: "abc" @deprecated = "abc"
30+
val y: "abc" = x
31+
}
32+
2633
object Test {
2734
class M {
2835
def m: Int = ???

0 commit comments

Comments
 (0)