diff --git a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala index e27d4afe1142..478ed94367fc 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala @@ -324,8 +324,15 @@ class ExtractSemanticDB extends Phase: if content.lift(span.end - 1).map(_ == '`').getOrElse(false) then (span.start + 1, span.end - 1) else (span.start, span.end) - val target = if sym.isPackageObject then sym.owner else sym - content.slice(start, end).mkString == target.name.stripModuleClassSuffix.lastPart.toString + val nameInSource = content.slice(start, end).mkString + // for secondary constructors `this` + if sym.isConstructor && nameInSource == nme.THISkw.toString then + true + else + val target = + if sym.isPackageObject then sym.owner + else sym + nameInSource == target.name.stripModuleClassSuffix.lastPart.toString private def spanOfSymbol(sym: Symbol, span: Span, treeSource: SourceFile)(using Context): Span = val contents = if treeSource.exists then treeSource.content() else Array.empty[Char] diff --git a/tests/semanticdb/expect/Annotations.expect.scala b/tests/semanticdb/expect/Annotations.expect.scala index 29b95cec73ca..14976ad8aa2f 100644 --- a/tests/semanticdb/expect/Annotations.expect.scala +++ b/tests/semanticdb/expect/Annotations.expect.scala @@ -21,7 +21,7 @@ class Annotations/*<-annot::Annotations#*/[@TypeParameterAnnotation/*->com::java class B/*<-annot::B#*/ @ConstructorAnnotation/*->com::javacp::annot::ConstructorAnnotation#*/()(x/*<-annot::B#x.*/: Int/*->scala::Int#*/) { @ConstructorAnnotation/*->com::javacp::annot::ConstructorAnnotation#*/ - def this() = this(42) + def this/*<-annot::B#``(+1).*/() = this(42) } @ObjectAnnotation/*->com::javacp::annot::ObjectAnnotation#*/ diff --git a/tests/semanticdb/expect/EndMarkers.expect.scala b/tests/semanticdb/expect/EndMarkers.expect.scala index fee8f06f3671..7ace3ceae22f 100644 --- a/tests/semanticdb/expect/EndMarkers.expect.scala +++ b/tests/semanticdb/expect/EndMarkers.expect.scala @@ -1,9 +1,9 @@ package endmarkers: class MultiCtor/*<-endmarkers::MultiCtor#*/(val i/*<-endmarkers::MultiCtor#i.*/: Int/*->scala::Int#*/): - def this() = + def this/*<-endmarkers::MultiCtor#``(+1).*/() = this(23) - end this + end this/*->endmarkers::MultiCtor#``(+1).*/ end MultiCtor/*->endmarkers::MultiCtor#*/ def topLevelMethod/*<-endmarkers::EndMarkers$package.topLevelMethod().*/: String/*->scala::Predef.String#*/ = diff --git a/tests/semanticdb/expect/semanticdb-Flags.expect.scala b/tests/semanticdb/expect/semanticdb-Flags.expect.scala index 384e59496967..99a7cbdddfb6 100644 --- a/tests/semanticdb/expect/semanticdb-Flags.expect.scala +++ b/tests/semanticdb/expect/semanticdb-Flags.expect.scala @@ -8,8 +8,8 @@ package object p/*<-flags::p::package.*/ { def z/*<-flags::p::package.z().*/(pp/*<-flags::p::package.z().(pp)*/: Int/*->scala::Int#*/) = 3 def m/*<-flags::p::package.m().*/[TT/*<-flags::p::package.m().[TT]*/]: Int/*->scala::Int#*/ = macro ???/*->scala::Predef.`???`().*/ abstract class C/*<-flags::p::package.C#*/[+T/*<-flags::p::package.C#[T]*/, -U/*<-flags::p::package.C#[U]*/, V/*<-flags::p::package.C#[V]*/](x/*<-flags::p::package.C#x.*/: T/*->flags::p::package.C#[T]*/, y/*<-flags::p::package.C#y.*/: U/*->flags::p::package.C#[U]*/, z/*<-flags::p::package.C#z.*/: V/*->flags::p::package.C#[V]*/) { - def this() = this(???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/) - def this(t/*<-flags::p::package.C#``(+2).(t)*/: T/*->flags::p::package.C#[T]*/) = this(t/*->flags::p::package.C#``(+2).(t)*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/) + def this/*<-flags::p::package.C#``(+1).*/() = this(???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/) + def this/*<-flags::p::package.C#``(+2).*/(t/*<-flags::p::package.C#``(+2).(t)*/: T/*->flags::p::package.C#[T]*/) = this(t/*->flags::p::package.C#``(+2).(t)*/, ???/*->scala::Predef.`???`().*/, ???/*->scala::Predef.`???`().*/) def w/*<-flags::p::package.C#w().*/: Int/*->scala::Int#*/ } type T1/*<-flags::p::package.T1#*/ = Int/*->scala::Int#*/ diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 9219ea1a1a04..f0c8aa6aa28d 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -210,7 +210,7 @@ Uri => Annotations.scala Text => empty Language => Scala Symbols => 22 entries -Occurrences => 47 entries +Occurrences => 48 entries Symbols: annot/Alias. => final object Alias extends Object { self: Alias.type => +2 decls } @@ -271,6 +271,7 @@ Occurrences: [21:33..21:34): x <- annot/B#x. [21:36..21:39): Int -> scala/Int# [22:3..22:24): ConstructorAnnotation -> com/javacp/annot/ConstructorAnnotation# +[23:6..23:10): <- annot/B#``(+1). [26:1..26:17): ObjectAnnotation -> com/javacp/annot/ObjectAnnotation# [27:7..27:8): M <- annot/M. [28:3..28:18): MacroAnnotation -> com/javacp/annot/MacroAnnotation# @@ -660,7 +661,7 @@ Uri => EndMarkers.scala Text => empty Language => Scala Symbols => 24 entries -Occurrences => 35 entries +Occurrences => 37 entries Symbols: endmarkers/Container# => class Container extends Object { self: Container => +5 decls } @@ -693,6 +694,8 @@ Occurrences: [2:8..2:17): MultiCtor <- endmarkers/MultiCtor# [2:22..2:23): i <- endmarkers/MultiCtor#i. [2:25..2:28): Int -> scala/Int# +[3:8..3:12): <- endmarkers/MultiCtor#``(+1). +[5:8..5:12): this -> endmarkers/MultiCtor#``(+1). [6:6..6:15): MultiCtor -> endmarkers/MultiCtor# [8:6..8:20): topLevelMethod <- endmarkers/EndMarkers$package.topLevelMethod(). [8:22..8:28): String -> scala/Predef.String# @@ -3881,7 +3884,7 @@ Uri => semanticdb-Flags.scala Text => empty Language => Scala Symbols => 50 entries -Occurrences => 71 entries +Occurrences => 73 entries Symbols: flags/p/package. => final package object p extends Object { self: p.type => +23 decls } @@ -3963,9 +3966,11 @@ Occurrences: [9:39..9:40): U -> flags/p/package.C#[U] [9:42..9:43): z <- flags/p/package.C#z. [9:45..9:46): V -> flags/p/package.C#[V] +[10:8..10:12): <- flags/p/package.C#``(+1). [10:22..10:25): ??? -> scala/Predef.`???`(). [10:27..10:30): ??? -> scala/Predef.`???`(). [10:32..10:35): ??? -> scala/Predef.`???`(). +[11:8..11:12): <- flags/p/package.C#``(+2). [11:13..11:14): t <- flags/p/package.C#``(+2).(t) [11:16..11:17): T -> flags/p/package.C#[T] [11:26..11:27): t -> flags/p/package.C#``(+2).(t)