Skip to content

Commit 5d3bdf3

Browse files
committed
Fix missing symbol occurrence of tparams' typebounds in constructor
1 parent 38b983c commit 5d3bdf3

File tree

5 files changed

+139
-4
lines changed

5 files changed

+139
-4
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class ExtractSemanticDB extends Phase:
185185
if !excludeDef(ctorSym) then
186186
traverseAnnotsOfDefinition(ctorSym)
187187
registerDefinition(ctorSym, tree.constr.nameSpan.startPos, Set.empty, tree.source)
188-
ctorParams(tree.constr.termParamss, tree.body)
188+
ctorParams(tree.constr.termParamss, tree.constr.leadingTypeParams, tree.body)
189189
for parent <- tree.parentsOrDerived if parent.span.hasLength do
190190
traverse(parent)
191191
val selfSpan = tree.self.span
@@ -619,7 +619,7 @@ class ExtractSemanticDB extends Phase:
619619
symkinds.toSet
620620

621621
private def ctorParams(
622-
vparamss: List[List[ValDef]], body: List[Tree])(using Context): Unit =
622+
vparamss: List[List[ValDef]], tparams: List[TypeDef], body: List[Tree])(using Context): Unit =
623623
@tu lazy val getters = findGetters(vparamss.flatMap(_.map(_.name)).toSet, body)
624624
for
625625
vparams <- vparamss
@@ -632,6 +632,8 @@ class ExtractSemanticDB extends Phase:
632632
if getter.mods.is(Mutable) then SymbolKind.VarSet else SymbolKind.ValSet)
633633
registerSymbol(vparam.symbol, symbolName(vparam.symbol), symkinds)
634634
traverse(vparam.tpt)
635+
tparams.foreach(tp => traverse(tp.rhs))
636+
635637

636638
object ExtractSemanticDB:
637639
import java.nio.file.Path
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// LazyRef
2+
trait Txn/*<-_empty_::Txn#*/[T/*<-_empty_::Txn#[T]*/ <: Txn/*->_empty_::Txn#*/[T/*->_empty_::Txn#[T]*/]]
3+
4+
trait Elem/*<-_empty_::Elem#*/[T/*<-_empty_::Elem#[T]*/ <: Txn/*->_empty_::Txn#*/[T/*->_empty_::Elem#[T]*/]]
5+
6+
trait Obj/*<-_empty_::Obj#*/[T/*<-_empty_::Obj#[T]*/ <: Txn/*->_empty_::Txn#*/[T/*->_empty_::Obj#[T]*/]] extends Elem/*->_empty_::Elem#*/[T/*->_empty_::Obj#[T]*/]
7+
8+
trait Copy/*<-_empty_::Copy#*/[In/*<-_empty_::Copy#[In]*/ <: Txn/*->_empty_::Txn#*/[In/*->_empty_::Copy#[In]*/], Out/*<-_empty_::Copy#[Out]*/ <: Txn/*->_empty_::Txn#*/[Out/*->_empty_::Copy#[Out]*/]] {
9+
def copyImpl/*<-_empty_::Copy#copyImpl().*/[Repr/*<-_empty_::Copy#copyImpl().[Repr]*/[~ <: Txn[~]] <: Elem[~]](in/*<-_empty_::Copy#copyImpl().(in)*/: Repr/*->_empty_::Copy#copyImpl().[Repr]*/[In/*->_empty_::Copy#[In]*/]): Repr/*->_empty_::Copy#copyImpl().[Repr]*/[Out/*->_empty_::Copy#[Out]*/]
10+
11+
def apply/*<-_empty_::Copy#apply().*/[Repr/*<-_empty_::Copy#apply().[Repr]*/[~ <: Txn[~]] <: Elem[~]](in/*<-_empty_::Copy#apply().(in)*/: Repr/*->_empty_::Copy#apply().[Repr]*/[In/*->_empty_::Copy#[In]*/]): Repr/*->_empty_::Copy#apply().[Repr]*/[Out/*->_empty_::Copy#[Out]*/] = {
12+
val out/*<-local0*/ = copyImpl/*->_empty_::Copy#copyImpl().*/[Repr/*->_empty_::Copy#apply().[Repr]*/](in/*->_empty_::Copy#apply().(in)*/)
13+
(/*->scala::Tuple2.apply().*/in/*->_empty_::Copy#apply().(in)*/, out/*->local0*/) match {
14+
case (/*->scala::Tuple2.unapply().*/inObj/*<-local1*/: Obj/*->_empty_::Obj#*/[In/*->_empty_::Copy#[In]*/], outObj/*<-local2*/: Obj/*->_empty_::Obj#*/[Out/*->_empty_::Copy#[Out]*/]) => // problem here
15+
println/*->scala::Predef.println(+1).*/("copy the attributes")
16+
case _ =>
17+
}
18+
out/*->local0*/
19+
}
20+
}

tests/semanticdb/expect/i9782.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// LazyRef
2+
trait Txn[T <: Txn[T]]
3+
4+
trait Elem[T <: Txn[T]]
5+
6+
trait Obj[T <: Txn[T]] extends Elem[T]
7+
8+
trait Copy[In <: Txn[In], Out <: Txn[Out]] {
9+
def copyImpl[Repr[~ <: Txn[~]] <: Elem[~]](in: Repr[In]): Repr[Out]
10+
11+
def apply[Repr[~ <: Txn[~]] <: Elem[~]](in: Repr[In]): Repr[Out] = {
12+
val out = copyImpl[Repr](in)
13+
(in, out) match {
14+
case (inObj: Obj[In], outObj: Obj[Out]) => // problem here
15+
println("copy the attributes")
16+
case _ =>
17+
}
18+
out
19+
}
20+
}

tests/semanticdb/expect/recursion.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Nats/*<-recursion::Nats.*/ {
1313
}
1414

1515
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#*/
16+
case class Succ/*<-recursion::Nats.Succ#*/[N/*<-recursion::Nats.Succ#[N]*/ <: Nat/*->recursion::Nats.Nat#*/](p/*<-recursion::Nats.Succ#p.*/: N/*->recursion::Nats.Succ#[N]*/) extends Nat/*->recursion::Nats.Nat#*/
1717

1818
transparent inline def toIntg/*<-recursion::Nats.toIntg().*/(inline n/*<-recursion::Nats.toIntg().(n)*/: Nat/*->recursion::Nats.Nat#*/): Int/*->scala::Int#*/ =
1919
inline n/*->recursion::Nats.toIntg().(n)*/ match {

tests/semanticdb/metac.expect

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3534,6 +3534,98 @@ Occurrences:
35343534
[4:12..4:16): Test -> i9727/Test#
35353535
[4:16..4:16): -> i9727/Test#`<init>`().
35363536

3537+
expect/i9782.scala
3538+
------------------
3539+
3540+
Summary:
3541+
Schema => SemanticDB v4
3542+
Uri => i9782.scala
3543+
Text => empty
3544+
Language => Scala
3545+
Symbols => 22 entries
3546+
Occurrences => 55 entries
3547+
3548+
Symbols:
3549+
_empty_/Copy# => trait Copy
3550+
_empty_/Copy#[In] => typeparam In
3551+
_empty_/Copy#[Out] => typeparam Out
3552+
_empty_/Copy#`<init>`(). => primary ctor <init>
3553+
_empty_/Copy#apply(). => method apply
3554+
_empty_/Copy#apply().(in) => param in
3555+
_empty_/Copy#apply().[Repr] => typeparam Repr
3556+
_empty_/Copy#copyImpl(). => abstract method copyImpl
3557+
_empty_/Copy#copyImpl().(in) => param in
3558+
_empty_/Copy#copyImpl().[Repr] => typeparam Repr
3559+
_empty_/Elem# => trait Elem
3560+
_empty_/Elem#[T] => typeparam T
3561+
_empty_/Elem#`<init>`(). => primary ctor <init>
3562+
_empty_/Obj# => trait Obj
3563+
_empty_/Obj#[T] => typeparam T
3564+
_empty_/Obj#`<init>`(). => primary ctor <init>
3565+
_empty_/Txn# => trait Txn
3566+
_empty_/Txn#[T] => typeparam T
3567+
_empty_/Txn#`<init>`(). => primary ctor <init>
3568+
local0 => val local out
3569+
local1 => val local inObj
3570+
local2 => val local outObj
3571+
3572+
Occurrences:
3573+
[1:6..1:9): Txn <- _empty_/Txn#
3574+
[1:9..1:9): <- _empty_/Txn#`<init>`().
3575+
[1:10..1:11): T <- _empty_/Txn#[T]
3576+
[1:15..1:18): Txn -> _empty_/Txn#
3577+
[1:19..1:20): T -> _empty_/Txn#[T]
3578+
[3:6..3:10): Elem <- _empty_/Elem#
3579+
[3:10..3:10): <- _empty_/Elem#`<init>`().
3580+
[3:11..3:12): T <- _empty_/Elem#[T]
3581+
[3:16..3:19): Txn -> _empty_/Txn#
3582+
[3:20..3:21): T -> _empty_/Elem#[T]
3583+
[5:6..5:9): Obj <- _empty_/Obj#
3584+
[5:9..5:9): <- _empty_/Obj#`<init>`().
3585+
[5:10..5:11): T <- _empty_/Obj#[T]
3586+
[5:15..5:18): Txn -> _empty_/Txn#
3587+
[5:19..5:20): T -> _empty_/Obj#[T]
3588+
[5:31..5:35): Elem -> _empty_/Elem#
3589+
[5:36..5:37): T -> _empty_/Obj#[T]
3590+
[7:6..7:10): Copy <- _empty_/Copy#
3591+
[7:10..7:10): <- _empty_/Copy#`<init>`().
3592+
[7:11..7:13): In <- _empty_/Copy#[In]
3593+
[7:17..7:20): Txn -> _empty_/Txn#
3594+
[7:21..7:23): In -> _empty_/Copy#[In]
3595+
[7:26..7:29): Out <- _empty_/Copy#[Out]
3596+
[7:33..7:36): Txn -> _empty_/Txn#
3597+
[7:37..7:40): Out -> _empty_/Copy#[Out]
3598+
[8:6..8:14): copyImpl <- _empty_/Copy#copyImpl().
3599+
[8:15..8:19): Repr <- _empty_/Copy#copyImpl().[Repr]
3600+
[8:45..8:47): in <- _empty_/Copy#copyImpl().(in)
3601+
[8:49..8:53): Repr -> _empty_/Copy#copyImpl().[Repr]
3602+
[8:54..8:56): In -> _empty_/Copy#[In]
3603+
[8:60..8:64): Repr -> _empty_/Copy#copyImpl().[Repr]
3604+
[8:65..8:68): Out -> _empty_/Copy#[Out]
3605+
[10:6..10:11): apply <- _empty_/Copy#apply().
3606+
[10:12..10:16): Repr <- _empty_/Copy#apply().[Repr]
3607+
[10:42..10:44): in <- _empty_/Copy#apply().(in)
3608+
[10:46..10:50): Repr -> _empty_/Copy#apply().[Repr]
3609+
[10:51..10:53): In -> _empty_/Copy#[In]
3610+
[10:57..10:61): Repr -> _empty_/Copy#apply().[Repr]
3611+
[10:62..10:65): Out -> _empty_/Copy#[Out]
3612+
[11:8..11:11): out <- local0
3613+
[11:14..11:22): copyImpl -> _empty_/Copy#copyImpl().
3614+
[11:23..11:27): Repr -> _empty_/Copy#apply().[Repr]
3615+
[11:29..11:31): in -> _empty_/Copy#apply().(in)
3616+
[12:5..12:5): -> scala/Tuple2.apply().
3617+
[12:5..12:7): in -> _empty_/Copy#apply().(in)
3618+
[12:9..12:12): out -> local0
3619+
[13:12..13:12): -> scala/Tuple2.unapply().
3620+
[13:12..13:17): inObj <- local1
3621+
[13:19..13:22): Obj -> _empty_/Obj#
3622+
[13:23..13:25): In -> _empty_/Copy#[In]
3623+
[13:28..13:34): outObj <- local2
3624+
[13:36..13:39): Obj -> _empty_/Obj#
3625+
[13:40..13:43): Out -> _empty_/Copy#[Out]
3626+
[14:8..14:15): println -> scala/Predef.println(+1).
3627+
[17:4..17:7): out -> local0
3628+
35373629
expect/inlineconsume.scala
35383630
--------------------------
35393631

@@ -3625,7 +3717,7 @@ Uri => recursion.scala
36253717
Text => empty
36263718
Language => Scala
36273719
Symbols => 36 entries
3628-
Occurrences => 56 entries
3720+
Occurrences => 57 entries
36293721

36303722
Symbols:
36313723
local0 => case val method N$1
@@ -3693,6 +3785,7 @@ Occurrences:
36933785
[15:13..15:17): Succ <- recursion/Nats.Succ#
36943786
[15:17..15:17): <- recursion/Nats.Succ#`<init>`().
36953787
[15:18..15:19): N <- recursion/Nats.Succ#[N]
3788+
[15:23..15:26): Nat -> recursion/Nats.Nat#
36963789
[15:28..15:29): p <- recursion/Nats.Succ#p.
36973790
[15:31..15:32): N -> recursion/Nats.Succ#[N]
36983791
[15:42..15:45): Nat -> recursion/Nats.Nat#

0 commit comments

Comments
 (0)