Skip to content

Commit

Permalink
Fix missing symbol occurrence of tparams' typebounds in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishiking committed Aug 11, 2021
1 parent 38b983c commit c67e283
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class ExtractSemanticDB extends Phase:
if !excludeDef(ctorSym) then
traverseAnnotsOfDefinition(ctorSym)
registerDefinition(ctorSym, tree.constr.nameSpan.startPos, Set.empty, tree.source)
ctorParams(tree.constr.termParamss, tree.body)
ctorParams(tree.constr.termParamss, tree.constr.leadingTypeParams, tree.body)
for parent <- tree.parentsOrDerived if parent.span.hasLength do
traverse(parent)
val selfSpan = tree.self.span
Expand Down Expand Up @@ -619,7 +619,7 @@ class ExtractSemanticDB extends Phase:
symkinds.toSet

private def ctorParams(
vparamss: List[List[ValDef]], body: List[Tree])(using Context): Unit =
vparamss: List[List[ValDef]], tparams: List[TypeDef], body: List[Tree])(using Context): Unit =
@tu lazy val getters = findGetters(vparamss.flatMap(_.map(_.name)).toSet, body)
for
vparams <- vparamss
Expand All @@ -632,6 +632,11 @@ class ExtractSemanticDB extends Phase:
if getter.mods.is(Mutable) then SymbolKind.VarSet else SymbolKind.ValSet)
registerSymbol(vparam.symbol, symbolName(vparam.symbol), symkinds)
traverse(vparam.tpt)
for
tparam <- tparams
do
traverse(tparam.rhs)


object ExtractSemanticDB:
import java.nio.file.Path
Expand Down
20 changes: 20 additions & 0 deletions tests/semanticdb/expect/i9782.expect.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// LazyRef
trait Txn/*<-_empty_::Txn#*/[T/*<-_empty_::Txn#[T]*/ <: Txn/*->_empty_::Txn#*/[T/*->_empty_::Txn#[T]*/]]

trait Elem/*<-_empty_::Elem#*/[T/*<-_empty_::Elem#[T]*/ <: Txn/*->_empty_::Txn#*/[T/*->_empty_::Elem#[T]*/]]

trait Obj/*<-_empty_::Obj#*/[T/*<-_empty_::Obj#[T]*/ <: Txn/*->_empty_::Txn#*/[T/*->_empty_::Obj#[T]*/]] extends Elem/*->_empty_::Elem#*/[T/*->_empty_::Obj#[T]*/]

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]*/]] {
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]*/]

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]*/] = {
val out/*<-local0*/ = copyImpl/*->_empty_::Copy#copyImpl().*/[Repr/*->_empty_::Copy#apply().[Repr]*/](in/*->_empty_::Copy#apply().(in)*/)
(/*->scala::Tuple2.apply().*/in/*->_empty_::Copy#apply().(in)*/, out/*->local0*/) match {
case (/*->scala::Tuple2.unapply().*/inObj/*<-local1*/: Obj/*->_empty_::Obj#*/[In/*->_empty_::Copy#[In]*/], outObj/*<-local2*/: Obj/*->_empty_::Obj#*/[Out/*->_empty_::Copy#[Out]*/]) => // problem here
println/*->scala::Predef.println(+1).*/("copy the attributes")
case _ =>
}
out/*->local0*/
}
}
20 changes: 20 additions & 0 deletions tests/semanticdb/expect/i9782.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// LazyRef
trait Txn[T <: Txn[T]]

trait Elem[T <: Txn[T]]

trait Obj[T <: Txn[T]] extends Elem[T]

trait Copy[In <: Txn[In], Out <: Txn[Out]] {
def copyImpl[Repr[~ <: Txn[~]] <: Elem[~]](in: Repr[In]): Repr[Out]

def apply[Repr[~ <: Txn[~]] <: Elem[~]](in: Repr[In]): Repr[Out] = {
val out = copyImpl[Repr](in)
(in, out) match {
case (inObj: Obj[In], outObj: Obj[Out]) => // problem here
println("copy the attributes")
case _ =>
}
out
}
}
2 changes: 1 addition & 1 deletion tests/semanticdb/expect/recursion.expect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object Nats/*<-recursion::Nats.*/ {
}

case object Zero/*<-recursion::Nats.Zero.*/ extends Nat/*->recursion::Nats.Nat#*/
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#*/
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#*/

transparent inline def toIntg/*<-recursion::Nats.toIntg().*/(inline n/*<-recursion::Nats.toIntg().(n)*/: Nat/*->recursion::Nats.Nat#*/): Int/*->scala::Int#*/ =
inline n/*->recursion::Nats.toIntg().(n)*/ match {
Expand Down
95 changes: 94 additions & 1 deletion tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -3534,6 +3534,98 @@ Occurrences:
[4:12..4:16): Test -> i9727/Test#
[4:16..4:16): -> i9727/Test#`<init>`().

expect/i9782.scala
------------------

Summary:
Schema => SemanticDB v4
Uri => i9782.scala
Text => empty
Language => Scala
Symbols => 22 entries
Occurrences => 55 entries

Symbols:
_empty_/Copy# => trait Copy
_empty_/Copy#[In] => typeparam In
_empty_/Copy#[Out] => typeparam Out
_empty_/Copy#`<init>`(). => primary ctor <init>
_empty_/Copy#apply(). => method apply
_empty_/Copy#apply().(in) => param in
_empty_/Copy#apply().[Repr] => typeparam Repr
_empty_/Copy#copyImpl(). => abstract method copyImpl
_empty_/Copy#copyImpl().(in) => param in
_empty_/Copy#copyImpl().[Repr] => typeparam Repr
_empty_/Elem# => trait Elem
_empty_/Elem#[T] => typeparam T
_empty_/Elem#`<init>`(). => primary ctor <init>
_empty_/Obj# => trait Obj
_empty_/Obj#[T] => typeparam T
_empty_/Obj#`<init>`(). => primary ctor <init>
_empty_/Txn# => trait Txn
_empty_/Txn#[T] => typeparam T
_empty_/Txn#`<init>`(). => primary ctor <init>
local0 => val local out
local1 => val local inObj
local2 => val local outObj

Occurrences:
[1:6..1:9): Txn <- _empty_/Txn#
[1:9..1:9): <- _empty_/Txn#`<init>`().
[1:10..1:11): T <- _empty_/Txn#[T]
[1:15..1:18): Txn -> _empty_/Txn#
[1:19..1:20): T -> _empty_/Txn#[T]
[3:6..3:10): Elem <- _empty_/Elem#
[3:10..3:10): <- _empty_/Elem#`<init>`().
[3:11..3:12): T <- _empty_/Elem#[T]
[3:16..3:19): Txn -> _empty_/Txn#
[3:20..3:21): T -> _empty_/Elem#[T]
[5:6..5:9): Obj <- _empty_/Obj#
[5:9..5:9): <- _empty_/Obj#`<init>`().
[5:10..5:11): T <- _empty_/Obj#[T]
[5:15..5:18): Txn -> _empty_/Txn#
[5:19..5:20): T -> _empty_/Obj#[T]
[5:31..5:35): Elem -> _empty_/Elem#
[5:36..5:37): T -> _empty_/Obj#[T]
[7:6..7:10): Copy <- _empty_/Copy#
[7:10..7:10): <- _empty_/Copy#`<init>`().
[7:11..7:13): In <- _empty_/Copy#[In]
[7:17..7:20): Txn -> _empty_/Txn#
[7:21..7:23): In -> _empty_/Copy#[In]
[7:26..7:29): Out <- _empty_/Copy#[Out]
[7:33..7:36): Txn -> _empty_/Txn#
[7:37..7:40): Out -> _empty_/Copy#[Out]
[8:6..8:14): copyImpl <- _empty_/Copy#copyImpl().
[8:15..8:19): Repr <- _empty_/Copy#copyImpl().[Repr]
[8:45..8:47): in <- _empty_/Copy#copyImpl().(in)
[8:49..8:53): Repr -> _empty_/Copy#copyImpl().[Repr]
[8:54..8:56): In -> _empty_/Copy#[In]
[8:60..8:64): Repr -> _empty_/Copy#copyImpl().[Repr]
[8:65..8:68): Out -> _empty_/Copy#[Out]
[10:6..10:11): apply <- _empty_/Copy#apply().
[10:12..10:16): Repr <- _empty_/Copy#apply().[Repr]
[10:42..10:44): in <- _empty_/Copy#apply().(in)
[10:46..10:50): Repr -> _empty_/Copy#apply().[Repr]
[10:51..10:53): In -> _empty_/Copy#[In]
[10:57..10:61): Repr -> _empty_/Copy#apply().[Repr]
[10:62..10:65): Out -> _empty_/Copy#[Out]
[11:8..11:11): out <- local0
[11:14..11:22): copyImpl -> _empty_/Copy#copyImpl().
[11:23..11:27): Repr -> _empty_/Copy#apply().[Repr]
[11:29..11:31): in -> _empty_/Copy#apply().(in)
[12:5..12:5): -> scala/Tuple2.apply().
[12:5..12:7): in -> _empty_/Copy#apply().(in)
[12:9..12:12): out -> local0
[13:12..13:12): -> scala/Tuple2.unapply().
[13:12..13:17): inObj <- local1
[13:19..13:22): Obj -> _empty_/Obj#
[13:23..13:25): In -> _empty_/Copy#[In]
[13:28..13:34): outObj <- local2
[13:36..13:39): Obj -> _empty_/Obj#
[13:40..13:43): Out -> _empty_/Copy#[Out]
[14:8..14:15): println -> scala/Predef.println(+1).
[17:4..17:7): out -> local0

expect/inlineconsume.scala
--------------------------

Expand Down Expand Up @@ -3625,7 +3717,7 @@ Uri => recursion.scala
Text => empty
Language => Scala
Symbols => 36 entries
Occurrences => 56 entries
Occurrences => 57 entries

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

0 comments on commit c67e283

Please sign in to comment.