From 72b1ab25ea6a14bbe4bd51c895477c799930b0d7 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Tue, 2 Jul 2024 16:56:38 +0200 Subject: [PATCH] fix: semanticdb symbol creation when `targetName` set [Cherry-picked 05f45b1475a56edbd54d0b037540b5ce6d46c64b] --- .../semanticdb/SemanticSymbolBuilder.scala | 3 +- .../semanticdb/expect/TargetName.expect.scala | 8 ++++ tests/semanticdb/expect/TargetName.scala | 8 ++++ tests/semanticdb/metac.expect | 37 +++++++++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/semanticdb/expect/TargetName.expect.scala create mode 100644 tests/semanticdb/expect/TargetName.scala diff --git a/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala b/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala index 50ea6ec48510..81f5d37f443f 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/SemanticSymbolBuilder.scala @@ -91,7 +91,8 @@ class SemanticSymbolBuilder: case _ => end find val sig = sym.signature - find(_.signature == sig) + val targetName = sym.targetName + find(sym => sym.signature == sig && sym.targetName == targetName) def addDescriptor(sym: Symbol): Unit = if sym.is(ModuleClass) then diff --git a/tests/semanticdb/expect/TargetName.expect.scala b/tests/semanticdb/expect/TargetName.expect.scala new file mode 100644 index 000000000000..d8bdf46bdc53 --- /dev/null +++ b/tests/semanticdb/expect/TargetName.expect.scala @@ -0,0 +1,8 @@ +package example + +object TargetName/*<-example::TargetName.*/: + @annotation.targetName/*->scala::annotation::targetName#*/("m1") + def m/*<-example::TargetName.m().*/(i/*<-example::TargetName.m().(i)*/: Int/*->scala::Int#*/) = 1 + @annotation.targetName/*->scala::annotation::targetName#*/("m2") + def m/*<-example::TargetName.m(+1).*/(i/*<-example::TargetName.m(+1).(i)*/: Int/*->scala::Int#*/) = 1 + def m1/*<-example::TargetName.m1().*/(i/*<-example::TargetName.m1().(i)*/: String/*->scala::Predef.String#*/) = 1 diff --git a/tests/semanticdb/expect/TargetName.scala b/tests/semanticdb/expect/TargetName.scala new file mode 100644 index 000000000000..5eef99283bb8 --- /dev/null +++ b/tests/semanticdb/expect/TargetName.scala @@ -0,0 +1,8 @@ +package example + +object TargetName: + @annotation.targetName("m1") + def m(i: Int) = 1 + @annotation.targetName("m2") + def m(i: Int) = 1 + def m1(i: String) = 1 diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 221422de6505..16f1b7c13d1f 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -3799,6 +3799,43 @@ Synthetics: .map => *[Int] [3:1..3:5):List => *.apply[Int] +expect/TargetName.scala +----------------------- + +Summary: +Schema => SemanticDB v4 +Uri => TargetName.scala +Text => empty +Language => Scala +Symbols => 7 entries +Occurrences => 15 entries + +Symbols: +example/TargetName. => final object TargetName extends Object { self: TargetName.type => +4 decls } +example/TargetName.m(). => @targetName method m (param i: Int): Int +example/TargetName.m().(i) => param i: Int +example/TargetName.m(+1). => @targetName method m (param i: Int): Int +example/TargetName.m(+1).(i) => param i: Int +example/TargetName.m1(). => method m1 (param i: String): Int +example/TargetName.m1().(i) => param i: String + +Occurrences: +[0:8..0:15): example <- example/ +[2:7..2:17): TargetName <- example/TargetName. +[3:3..3:13): annotation -> scala/annotation/ +[3:14..3:24): targetName -> scala/annotation/targetName# +[4:6..4:7): m <- example/TargetName.m(). +[4:8..4:9): i <- example/TargetName.m().(i) +[4:11..4:14): Int -> scala/Int# +[5:3..5:13): annotation -> scala/annotation/ +[5:14..5:24): targetName -> scala/annotation/targetName# +[6:6..6:7): m <- example/TargetName.m(+1). +[6:8..6:9): i <- example/TargetName.m(+1).(i) +[6:11..6:14): Int -> scala/Int# +[7:6..7:8): m1 <- example/TargetName.m1(). +[7:9..7:10): i <- example/TargetName.m1().(i) +[7:12..7:18): String -> scala/Predef.String# + expect/Traits.scala -------------------