From c67e283e8177a83c54423b82174644706593213d Mon Sep 17 00:00:00 2001 From: Rikito Taniguchi Date: Wed, 11 Aug 2021 23:12:25 +0900 Subject: [PATCH] Fix missing symbol occurrence of tparams' typebounds in constructor --- .../dotc/semanticdb/ExtractSemanticDB.scala | 9 +- tests/semanticdb/expect/i9782.expect.scala | 20 ++++ tests/semanticdb/expect/i9782.scala | 20 ++++ .../semanticdb/expect/recursion.expect.scala | 2 +- tests/semanticdb/metac.expect | 95 ++++++++++++++++++- 5 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 tests/semanticdb/expect/i9782.expect.scala create mode 100644 tests/semanticdb/expect/i9782.scala diff --git a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala index 710f3493b418..48aed757edfb 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala @@ -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 @@ -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 @@ -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 diff --git a/tests/semanticdb/expect/i9782.expect.scala b/tests/semanticdb/expect/i9782.expect.scala new file mode 100644 index 000000000000..98dbcfd21f5d --- /dev/null +++ b/tests/semanticdb/expect/i9782.expect.scala @@ -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*/ + } +} diff --git a/tests/semanticdb/expect/i9782.scala b/tests/semanticdb/expect/i9782.scala new file mode 100644 index 000000000000..8004300491cd --- /dev/null +++ b/tests/semanticdb/expect/i9782.scala @@ -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 + } +} diff --git a/tests/semanticdb/expect/recursion.expect.scala b/tests/semanticdb/expect/recursion.expect.scala index aba74b1b032e..88eeffa0c43a 100644 --- a/tests/semanticdb/expect/recursion.expect.scala +++ b/tests/semanticdb/expect/recursion.expect.scala @@ -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 { diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index ff519d6b832d..83ca95f61af8 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -3534,6 +3534,98 @@ Occurrences: [4:12..4:16): Test -> i9727/Test# [4:16..4:16): -> i9727/Test#``(). +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#``(). => primary ctor +_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#``(). => primary ctor +_empty_/Obj# => trait Obj +_empty_/Obj#[T] => typeparam T +_empty_/Obj#``(). => primary ctor +_empty_/Txn# => trait Txn +_empty_/Txn#[T] => typeparam T +_empty_/Txn#``(). => primary ctor +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#``(). +[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#``(). +[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#``(). +[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#``(). +[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 -------------------------- @@ -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 @@ -3693,6 +3785,7 @@ Occurrences: [15:13..15:17): Succ <- recursion/Nats.Succ# [15:17..15:17): <- recursion/Nats.Succ#``(). [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#