Skip to content

Commit 49daf3c

Browse files
committed
fix: remove duplicated type apply synthetics
fix: scalameta/metals#4372
1 parent 77c1d1e commit 49daf3c

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@ object Scala3:
222222
case NameKinds.AnyNumberedName(nme.EMPTY, _) => true
223223
case _ => false
224224
}
225+
226+
def isDynamic(using Context): Boolean =
227+
name == nme.applyDynamic ||
228+
name == nme.selectDynamic ||
229+
name == nme.updateDynamic ||
230+
name == nme.applyDynamicNamed
225231
end NameOps
226232

227233
given SymbolOps: AnyRef with

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import dotty.tools.dotc.ast.tpd._
44
import dotty.tools.dotc.core.Contexts._
55
import dotty.tools.dotc.core.Flags._
66
import dotty.tools.dotc.core.StdNames.nme
7+
import dotty.tools.dotc.core.NameKinds
78
import dotty.tools.dotc.{semanticdb => s}
89

910

@@ -27,7 +28,20 @@ class SyntheticsExtractor:
2728
case tree: TypeApply
2829
if tree.span.isSynthetic &&
2930
tree.args.forall(arg => !arg.symbol.isDefinedInSource) &&
30-
!tree.span.isZeroExtent =>
31+
!tree.span.isZeroExtent &&
32+
(tree.fun match {
33+
// for `Bar[Int]` of `class Foo extends Bar[Int]`
34+
// we'll have `TypeTree(Select(New(AppliedTypeTree(...))), List(Int))`
35+
// in this case, don't register `*[Int]` to synthetics as we already have `[Int]` in source.
36+
case Select(New(AppliedTypeTree(_, _)), _) => false
37+
38+
// for `new SomeJavaClass[Int]()`
39+
// there will be a synthesized default getter
40+
// in addition to the source derived one.
41+
case Select(_, name) if name.is(NameKinds.DefaultGetterName) => false
42+
case Select(fun, _) if fun.symbol.name.isDynamic => false
43+
case _ => true
44+
}) =>
3145
visited.add(tree)
3246
val fnTree = tree.fun match
3347
// Something like `List.apply[Int](1,2,3)`

tests/semanticdb/metac.expect

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Text => empty
5050
Language => Scala
5151
Symbols => 60 entries
5252
Occurrences => 132 entries
53-
Synthetics => 7 entries
53+
Synthetics => 3 entries
5454

5555
Symbols:
5656
advanced/C# => class C [typeparam T ] extends Object { self: C[T] => +3 decls }
@@ -249,13 +249,9 @@ Occurrences:
249249
[53:39..53:47): toString -> scala/Tuple2#toString().
250250

251251
Synthetics:
252-
[27:12..27:18):s.s1.x => *[Int]
253252
[27:12..27:16):s.s1 => reflectiveSelectable(*)
254-
[29:12..29:18):s.s2.x => *[Int]
255253
[29:12..29:16):s.s2 => reflectiveSelectable(*)
256-
[31:12..31:22):s.s3.m(??? => *[Int]
257254
[31:12..31:16):s.s3 => reflectiveSelectable(*)
258-
[47:19..47:24):foo.a => *[foo.A]
259255

260256
expect/Annotations.scala
261257
------------------------
@@ -267,7 +263,6 @@ Text => empty
267263
Language => Scala
268264
Symbols => 23 entries
269265
Occurrences => 52 entries
270-
Synthetics => 2 entries
271266

272267
Symbols:
273268
annot/Alias. => final object Alias extends Object { self: Alias.type => +2 decls }
@@ -348,10 +343,6 @@ Occurrences:
348343
[39:11..39:26): ClassAnnotation -> com/javacp/annot/ClassAnnotation#
349344
[39:28..39:33): param -> scala/annotation/meta/param#
350345

351-
Synthetics:
352-
[25:2..25:20):@throws[Exception] => *[Exception]
353-
[25:2..25:20):@throws[Exception] => *[Exception]
354-
355346
expect/Anonymous.scala
356347
----------------------
357348

@@ -899,7 +890,7 @@ Text => empty
899890
Language => Scala
900891
Symbols => 181 entries
901892
Occurrences => 148 entries
902-
Synthetics => 8 entries
893+
Synthetics => 6 entries
903894

904895
Symbols:
905896
_empty_/Enums. => final object Enums extends Object { self: Enums.type => +30 decls }
@@ -1235,8 +1226,6 @@ Occurrences:
12351226
[68:25..68:31): Planet -> _empty_/Enums.Planet#
12361227

12371228
Synthetics:
1238-
[42:24..42:32):Tag[Int] => *[Int]
1239-
[43:28..43:40):Tag[Boolean] => *[Boolean]
12401229
[52:9..52:13):Refl => *.unapply[Option[B]]
12411230
[52:31..52:50):identity[Option[B]] => *[Function1[A, Option[B]]]
12421231
[54:14..54:18):Some => *.apply[Some[Int]]
@@ -1288,7 +1277,6 @@ Text => empty
12881277
Language => Scala
12891278
Symbols => 5 entries
12901279
Occurrences => 23 entries
1291-
Synthetics => 2 entries
12921280

12931281
Symbols:
12941282
example/Example. => final object Example extends Object { self: Example.type => +3 decls }
@@ -1322,10 +1310,6 @@ Occurrences:
13221310
[9:24..9:32): classTag -> scala/reflect/package.classTag().
13231311
[9:33..9:36): Int -> scala/Int#
13241312

1325-
Synthetics:
1326-
[5:6..5:41):scala.collection.mutable.Stack[Int] => *[Int]
1327-
[5:6..5:41):scala.collection.mutable.Stack[Int] => *[Int]
1328-
13291313
expect/Extension.scala
13301314
----------------------
13311315

@@ -2228,7 +2212,7 @@ Text => empty
22282212
Language => Scala
22292213
Symbols => 3 entries
22302214
Occurrences => 80 entries
2231-
Synthetics => 5 entries
2215+
Synthetics => 2 entries
22322216

22332217
Symbols:
22342218
example/MethodUsages# => class MethodUsages extends Object { self: MethodUsages => +2 decls }
@@ -2318,11 +2302,8 @@ Occurrences:
23182302
[34:8..34:9): m -> example/Methods#m17.m().
23192303

23202304
Synthetics:
2321-
[3:14..3:26):Methods[Int] => *[Int]
2322-
[11:11..11:22):m.List[Int] => *[Int]
23232305
[13:2..13:6):m.m7 => *[Int]
23242306
[13:2..13:26):m.m7(m, new m.List[Int]) => *(Int)
2325-
[13:14..13:25):m.List[Int] => *[Int]
23262307

23272308
expect/Methods.scala
23282309
--------------------
@@ -4215,7 +4196,7 @@ Text => empty
42154196
Language => Scala
42164197
Symbols => 17 entries
42174198
Occurrences => 29 entries
4218-
Synthetics => 2 entries
4199+
Synthetics => 1 entries
42194200

42204201
Symbols:
42214202
_empty_/Concrete# => class Concrete extends NullaryTest[Int, List] { self: Concrete => +3 decls }
@@ -4268,7 +4249,6 @@ Occurrences:
42684249
[18:17..18:25): nullary3 -> _empty_/Concrete#nullary3().
42694250

42704251
Synthetics:
4271-
[11:23..11:45):NullaryTest[Int, List] => *[Int, List]
42724252
[13:17..13:21):List => *.apply[Int]
42734253

42744254
expect/recursion.scala

0 commit comments

Comments
 (0)