Skip to content

Commit 8c8eae9

Browse files
authored
[SemanticDB] fix regression in type apply synthetics (#16031)
This PR fixes the regressions in SemanticDB's TypeApply synthetics introduced by #15877 - e835dc0 - 097b179 - 097b179 Previously, we relies on `Scala2` flag for filtering out some synthetics, which isn't reliable for SemanticDB (that's why the capture checking made a change in how the compiler put flags to symbols and the regression occurred). This PR fixes the regression by re-implements TypeApply synthetics without using `Scala2` flag. (also fix scalameta/metals#4372) Probably, it makes more sense to compare the `metac.expect`'s diff from 53e1adc which was something before the regression. <details> <summary>diff from 53e1adc</summary> `git diff 53e1adc HEAD tests/semanticdb/metac.expect` ```diff diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index 5e20650..2c7f720 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -50,7 +50,7 @@ Text => empty Language => Scala Symbols => 60 entries Occurrences => 132 entries -Synthetics => 4 entries +Synthetics => 3 entries Symbols: advanced/C# => class C [typeparam T ] extends Object { self: C[T] => +3 decls } @@ -252,7 +252,6 @@ Synthetics: [27:12..27:16):s.s1 => reflectiveSelectable(*) [29:12..29:16):s.s2 => reflectiveSelectable(*) [31:12..31:16):s.s3 => reflectiveSelectable(*) -[47:19..47:24):foo.a => *[foo.A] expect/Annotations.scala ------------------------ @@ -264,7 +263,6 @@ Text => empty Language => Scala Symbols => 23 entries Occurrences => 52 entries -Synthetics => 2 entries Symbols: annot/Alias. => final object Alias extends Object { self: Alias.type => +2 decls } @@ -345,10 +343,6 @@ Occurrences: [39:11..39:26): ClassAnnotation -> com/javacp/annot/ClassAnnotation# [39:28..39:33): param -> scala/annotation/meta/param# -Synthetics: -[25:2..25:20):@throws[Exception] => *[Exception] -[25:2..25:20):@throws[Exception] => *[Exception] - expect/Anonymous.scala ---------------------- @@ -896,7 +890,7 @@ Text => empty Language => Scala Symbols => 181 entries Occurrences => 148 entries -Synthetics => 10 entries +Synthetics => 6 entries Symbols: _empty_/Enums. => final object Enums extends Object { self: Enums.type => +30 decls } @@ -1232,16 +1226,12 @@ Occurrences: [68:25..68:31): Planet -> _empty_/Enums.Planet# Synthetics: -[46:28..46:35):C <:< C => *[C, C] -[49:27..49:31):Refl => *.apply[T] [52:9..52:13):Refl => *.unapply[Option[B]] -[52:19..52:30):opt.flatMap => *[B] [52:31..52:50):identity[Option[B]] => *[Function1[A, Option[B]]] [54:14..54:18):Some => *.apply[Some[Int]] [54:14..54:34):Some(Some(1)).unwrap => *(given_<:<_T_T[Option[Int]]) [54:19..54:23):Some => *.apply[Int] [54:28..54:34):unwrap => *[Some[Int], Int] -[56:52..56:64):Enum[Planet] => *[Planet] expect/EtaExpansion.scala ------------------------- @@ -3165,7 +3155,7 @@ Text => empty Language => Scala Symbols => 52 entries Occurrences => 132 entries -Synthetics => 36 entries +Synthetics => 39 entries Symbols: example/Synthetic# => class Synthetic extends Object { self: Synthetic => +23 decls } @@ -3361,12 +3351,15 @@ Synthetics: [6:2..6:18):Array.empty[Int] => intArrayOps(*) [7:2..7:8):"fooo" => augmentString(*) [10:13..10:24):"name:(.*)" => augmentString(*) +[11:8..11:11):#:: => *.unapply[Int] [11:17..11:25):LazyList => *.apply[Int] [13:4..13:28):#:: 2 #:: LazyList.empty => *[Int] [13:8..13:28):2 #:: LazyList.empty => toDeferrer[Int](*) [13:10..13:28):#:: LazyList.empty => *[Int] [13:14..13:28):LazyList.empty => toDeferrer[Nothing](*) [13:14..13:28):LazyList.empty => *[Nothing] +[15:9..15:12):#:: => *.unapply[Int] +[15:16..15:19):#:: => *.unapply[Int] [15:25..15:33):LazyList => *.apply[Int] [17:14..17:38):#:: 2 #:: LazyList.empty => *[Int] [17:18..17:38):2 #:: LazyList.empty => toDeferrer[Int](*) @@ -3471,7 +3464,7 @@ Text => empty Language => Scala Symbols => 22 entries Occurrences => 46 entries -Synthetics => 7 entries +Synthetics => 11 entries Symbols: example/ValPattern# => class ValPattern extends Object { self: ValPattern => +14 decls } @@ -3546,12 +3539,16 @@ Occurrences: [40:10..40:18): rightVar -> local4 Synthetics: +[5:6..5:10):Some => *.unapply[Int] [6:4..6:8):Some => *.apply[Int] [8:6..8:10):List => *.unapplySeq[Nothing] [8:11..8:15):Some => *.unapply[Nothing] +[11:6..11:10):Some => *.unapply[Int] [12:4..12:8):Some => *.apply[Int] [25:4..25:11):locally => *[Unit] +[27:10..27:14):Some => *.unapply[Int] [28:8..28:12):Some => *.apply[Int] +[31:10..31:14):Some => *.unapply[Int] [32:8..32:12):Some => *.apply[Int] expect/Vals.scala @@ -4264,7 +4261,6 @@ Text => empty Language => Scala Symbols => 36 entries Occurrences => 46 entries -Synthetics => 3 entries Symbols: local0 => type N$1 <: Nat @@ -4352,11 +4348,6 @@ Occurrences: [23:35..23:39): Zero -> recursion/Nats.Zero. [23:40..23:42): ++ -> recursion/Nats.Nat#`++`(). -Synthetics: -[5:50..5:54):Succ => *.apply[Nat.this.type] -[10:13..10:17):Succ => *.unapply[N$1] -[20:11..20:15):Succ => *.unapply[N$2] - expect/semanticdb-Definitions.scala ----------------------------------- ``` </details>
2 parents 8c80350 + 49daf3c commit 8c8eae9

File tree

3 files changed

+111
-27
lines changed

3 files changed

+111
-27
lines changed

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

+6
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

+16-2
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

@@ -26,8 +27,21 @@ class SyntheticsExtractor:
2627
tree match
2728
case tree: TypeApply
2829
if tree.span.isSynthetic &&
29-
tree.args.forall(arg => !arg.symbol.is(Scala2x)) &&
30-
!tree.span.isZeroExtent =>
30+
tree.args.forall(arg => !arg.symbol.isDefinedInSource) &&
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)`

0 commit comments

Comments
 (0)