Skip to content

Commit c327d79

Browse files
committed
exclude top level wrapper objects
set the Synthetic flag on top level wrapper objects. fixes #11693, top level definition wrapper objects no longer appear as a definition occurrence in semanticdb, but are still recorded as a symbol
1 parent f0aa7a9 commit c327d79

11 files changed

+26
-26
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,9 @@ object desugar {
13011301
if (nestedStats.isEmpty) pdef
13021302
else {
13031303
val name = packageObjectName(ctx.source)
1304-
val grouped = ModuleDef(name, Template(emptyConstructor, Nil, Nil, EmptyValDef, nestedStats))
1304+
val grouped =
1305+
ModuleDef(name, Template(emptyConstructor, Nil, Nil, EmptyValDef, nestedStats))
1306+
.withMods(Modifiers(Synthetic))
13051307
cpy.PackageDef(pdef)(pdef.pid, topStats :+ grouped)
13061308
}
13071309
}

tests/semanticdb/expect/AnonymousGiven.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ package angiven
22

33
trait Foo/*<-angiven::Foo#*/
44

5-
/*<-angiven::AnonymousGiven$package.*/def bar/*<-angiven::AnonymousGiven$package.bar().*/(using Foo/*->angiven::Foo#*/) = 42
5+
def bar/*<-angiven::AnonymousGiven$package.bar().*/(using Foo/*->angiven::Foo#*/) = 42

tests/semanticdb/expect/EndMarkers.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package endmarkers:
66
end this/*->endmarkers::MultiCtor#`<init>`(+1).*/
77
end MultiCtor/*->endmarkers::MultiCtor#*/
88

9-
/*<-endmarkers::EndMarkers$package.*/def topLevelMethod/*<-endmarkers::EndMarkers$package.topLevelMethod().*/: String/*->scala::Predef.String#*/ =
9+
def topLevelMethod/*<-endmarkers::EndMarkers$package.topLevelMethod().*/: String/*->scala::Predef.String#*/ =
1010
"hello"
1111
end topLevelMethod/*->endmarkers::EndMarkers$package.topLevelMethod().*/
1212

tests/semanticdb/expect/Extension.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ext
22

3-
/*<-ext::Extension$package.*/extension (s/*<-ext::Extension$package.foo().(s)*//*<-ext::Extension$package.`#*#`().(s)*/: String/*->scala::Predef.String#*/)
3+
extension (s/*<-ext::Extension$package.foo().(s)*//*<-ext::Extension$package.`#*#`().(s)*/: String/*->scala::Predef.String#*/)
44
def foo/*<-ext::Extension$package.foo().*/: Int/*->scala::Int#*/ = 42
55
def #*#/*<-ext::Extension$package.`#*#`().*/ (i/*<-ext::Extension$package.`#*#`().(i)*/: Int/*->scala::Int#*/): (String/*->scala::Predef.String#*/, Int/*->scala::Int#*/) = (/*->scala::Tuple2.apply().*/s/*->ext::Extension$package.`#*#`().(s)*/, i/*->ext::Extension$package.`#*#`().(i)*/)
66

tests/semanticdb/expect/InventedNames.expect.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait Z/*<-givens::Z#*/[T/*<-givens::Z#[T]*/]:
1111

1212

1313

14-
/*<-givens::InventedNames$package.*/given intValue/*<-givens::InventedNames$package.intValue.*/: Int/*->scala::Int#*/ = 4
14+
given intValue/*<-givens::InventedNames$package.intValue.*/: Int/*->scala::Int#*/ = 4
1515
given /*<-givens::InventedNames$package.given_String.*/String/*->scala::Predef.String#*/ = "str"
1616
given /*<-givens::InventedNames$package.given_Double().*/(using Int/*->scala::Int#*/): Double/*->scala::Double#*/ = 4.0
1717
given /*<-givens::InventedNames$package.given_List_T().*/[T/*<-givens::InventedNames$package.given_List_T().[T]*/]: List/*->scala::package.List#*/[T/*->givens::InventedNames$package.given_List_T().[T]*/] = Nil/*->scala::package.Nil.*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package ext
22

3-
/*<-ext::RightAssociativeExtension$package.*/extension (s/*<-ext::RightAssociativeExtension$package.`:*:`().(s)*/: String/*->scala::Predef.String#*/)
3+
extension (s/*<-ext::RightAssociativeExtension$package.`:*:`().(s)*/: String/*->scala::Predef.String#*/)
44
def :*:/*<-ext::RightAssociativeExtension$package.`:*:`().*/ (i/*<-ext::RightAssociativeExtension$package.`:*:`().(i)*/: Int/*->scala::Int#*/): (String/*->scala::Predef.String#*/, Int/*->scala::Int#*/) = (/*->scala::Tuple2.apply().*/s/*->ext::RightAssociativeExtension$package.`:*:`().(s)*/, i/*->ext::RightAssociativeExtension$package.`:*:`().(i)*/)
55

66
val b/*<-ext::RightAssociativeExtension$package.b.*/ = "foo" :*:/*->ext::RightAssociativeExtension$package.`:*:`().*/ 23
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package exports
22

3-
/*<-exports::`exports-package$package`.*/export example.{Decoder/*<-exports::`exports-package$package`.Decoder#*/, Encoder/*<-exports::`exports-package$package`.Encoder#*/, Codec/*<-exports::`exports-package$package`.Codec#*/}
3+
export example.{Decoder/*<-exports::`exports-package$package`.Decoder#*/, Encoder/*<-exports::`exports-package$package`.Encoder#*/, Codec/*<-exports::`exports-package$package`.Codec#*/}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package i9727
22

33
class Test/*<-i9727::Test#*/(a/*<-i9727::Test#a.*/: Int/*->scala::Int#*/)
4-
/*<-i9727::i9727$package.*/val a/*<-i9727::i9727$package.a.*/ = new Test/*->i9727::Test#*/(1)
4+
val a/*<-i9727::i9727$package.a.*/ = new Test/*->i9727::Test#*/(1)
55
val b/*<-i9727::i9727$package.b.*/ = new Test/*->i9727::Test#*/(2)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
/*<-_empty_::toplevel$package.*/inline val a/*<-_empty_::toplevel$package.a.*/ = ""
1+
inline val a/*<-_empty_::toplevel$package.a.*/ = ""
22
extension (x/*<-_empty_::toplevel$package.combine().(x)*/: Int/*->scala::Int#*/) def combine/*<-_empty_::toplevel$package.combine().*/ (y/*<-_empty_::toplevel$package.combine().(y)*/: Int/*->scala::Int#*/) = x/*->_empty_::toplevel$package.combine().(x)*/ +/*->scala::Int#`+`(+4).*/ y/*->_empty_::toplevel$package.combine().(y)*/
33
def combine/*<-_empty_::toplevel$package.combine(+1).*/(x/*<-_empty_::toplevel$package.combine(+1).(x)*/: Int/*->scala::Int#*/, y/*<-_empty_::toplevel$package.combine(+1).(y)*/: Int/*->scala::Int#*/, z/*<-_empty_::toplevel$package.combine(+1).(z)*/: Int/*->scala::Int#*/) = x/*->_empty_::toplevel$package.combine(+1).(x)*/ +/*->scala::Int#`+`(+4).*/ y/*->_empty_::toplevel$package.combine(+1).(y)*/ +/*->scala::Int#`+`(+4).*/ z/*->_empty_::toplevel$package.combine(+1).(z)*/
44
def combine/*<-_empty_::toplevel$package.combine(+2).*/ = 0
55
def foo/*<-_empty_::toplevel$package.foo().*/ = "foo"
66
/*<-_empty_::MyProgram#*//*->_empty_::toplevel$package.MyProgram().*//*->scala::util::CommandLineParser.parseArgument().*//*->_empty_::MyProgram#main().(args)*//*->scala::util::CommandLineParser.FromString.given_FromString_Int.*//*->scala::util::CommandLineParser.showError().*//*->local0*/@main/*->scala::main#*/ def MyProgram/*<-_empty_::toplevel$package.MyProgram().*/(times/*<-_empty_::toplevel$package.MyProgram().(times)*/: Int/*->scala::Int#*/): Unit/*->scala::Unit#*/ = (/*->scala::LowPriorityImplicits#intWrapper().*/1 to/*->scala::runtime::RichInt#to().*/ times/*->_empty_::toplevel$package.MyProgram().(times)*/) foreach/*->scala::collection::immutable::Range#foreach().*/ (_ => println/*->scala::Predef.println(+1).*/("hello"))
7+
def fooRef/*<-_empty_::toplevel$package.fooRef().*/ = toplevel$package/*->_empty_::toplevel$package.*/.foo/*->_empty_::toplevel$package.foo().*/

tests/semanticdb/expect/toplevel.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ def combine(x: Int, y: Int, z: Int) = x + y + z
44
def combine = 0
55
def foo = "foo"
66
@main def MyProgram(times: Int): Unit = (1 to times) foreach (_ => println("hello"))
7+
def fooRef = toplevel$package.foo

tests/semanticdb/metac.expect

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ Uri => AnonymousGiven.scala
338338
Text => empty
339339
Language => Scala
340340
Symbols => 5 entries
341-
Occurrences => 6 entries
341+
Occurrences => 5 entries
342342

343343
Symbols:
344344
angiven/AnonymousGiven$package. => final package object angiven
@@ -351,7 +351,6 @@ Occurrences:
351351
[0:8..0:15): angiven <- angiven/
352352
[2:0..2:0): <- angiven/Foo#`<init>`().
353353
[2:6..2:9): Foo <- angiven/Foo#
354-
[4:0..4:0): <- angiven/AnonymousGiven$package.
355354
[4:4..4:7): bar <- angiven/AnonymousGiven$package.bar().
356355
[4:14..4:17): Foo -> angiven/Foo#
357356

@@ -667,7 +666,7 @@ Uri => EndMarkers.scala
667666
Text => empty
668667
Language => Scala
669668
Symbols => 24 entries
670-
Occurrences => 43 entries
669+
Occurrences => 42 entries
671670

672671
Symbols:
673672
endmarkers/Container# => class Container
@@ -705,7 +704,6 @@ Occurrences:
705704
[4:11..4:11): -> endmarkers/MultiCtor#`<init>`().
706705
[5:8..5:12): this -> endmarkers/MultiCtor#`<init>`(+1).
707706
[6:6..6:15): MultiCtor -> endmarkers/MultiCtor#
708-
[8:2..8:2): <- endmarkers/EndMarkers$package.
709707
[8:6..8:20): topLevelMethod <- endmarkers/EndMarkers$package.topLevelMethod().
710708
[8:22..8:28): String -> scala/Predef.String#
711709
[10:6..10:20): topLevelMethod -> endmarkers/EndMarkers$package.topLevelMethod().
@@ -1278,7 +1276,7 @@ Uri => Extension.scala
12781276
Text => empty
12791277
Language => Scala
12801278
Symbols => 8 entries
1281-
Occurrences => 19 entries
1279+
Occurrences => 18 entries
12821280

12831281
Symbols:
12841282
ext/Extension$package. => final package object ext
@@ -1292,7 +1290,6 @@ ext/Extension$package.foo().(s) => param s
12921290

12931291
Occurrences:
12941292
[0:8..0:11): ext <- ext/
1295-
[2:0..2:0): <- ext/Extension$package.
12961293
[2:11..2:12): s <- ext/Extension$package.foo().(s)
12971294
[2:11..2:12): s <- ext/Extension$package.`#*#`().(s)
12981295
[2:14..2:20): String -> scala/Predef.String#
@@ -1747,7 +1744,7 @@ Uri => InventedNames.scala
17471744
Text => empty
17481745
Language => Scala
17491746
Symbols => 45 entries
1750-
Occurrences => 73 entries
1747+
Occurrences => 72 entries
17511748

17521749
Symbols:
17531750
givens/InventedNames$package. => final package object givens
@@ -1812,7 +1809,6 @@ Occurrences:
18121809
[9:6..9:9): doZ <- givens/Z#doZ().
18131810
[9:11..9:15): List -> scala/package.List#
18141811
[9:16..9:17): T -> givens/Z#[T]
1815-
[13:0..13:0): <- givens/InventedNames$package.
18161812
[13:6..13:14): intValue <- givens/InventedNames$package.intValue.
18171813
[13:16..13:19): Int -> scala/Int#
18181814
[14:6..14:6): <- givens/InventedNames$package.given_String.
@@ -2731,7 +2727,7 @@ Uri => RightAssociativeExtension.scala
27312727
Text => empty
27322728
Language => Scala
27332729
Symbols => 5 entries
2734-
Occurrences => 14 entries
2730+
Occurrences => 13 entries
27352731

27362732
Symbols:
27372733
ext/RightAssociativeExtension$package. => final package object ext
@@ -2742,7 +2738,6 @@ ext/RightAssociativeExtension$package.b. => val method b
27422738

27432739
Occurrences:
27442740
[0:8..0:11): ext <- ext/
2745-
[2:0..2:0): <- ext/RightAssociativeExtension$package.
27462741
[2:11..2:12): s <- ext/RightAssociativeExtension$package.`:*:`().(s)
27472742
[2:14..2:20): String -> scala/Predef.String#
27482743
[3:6..3:9): :*: <- ext/RightAssociativeExtension$package.`:*:`().
@@ -3471,7 +3466,7 @@ Uri => exports-package.scala
34713466
Text => empty
34723467
Language => Scala
34733468
Symbols => 4 entries
3474-
Occurrences => 6 entries
3469+
Occurrences => 5 entries
34753470

34763471
Symbols:
34773472
exports/`exports-package$package`. => final package object exports
@@ -3481,7 +3476,6 @@ exports/`exports-package$package`.Encoder# => final type Encoder
34813476

34823477
Occurrences:
34833478
[0:8..0:15): exports <- exports/
3484-
[2:0..2:0): <- exports/`exports-package$package`.
34853479
[2:7..2:14): example -> exports/example/
34863480
[2:16..2:23): Decoder <- exports/`exports-package$package`.Decoder#
34873481
[2:25..2:32): Encoder <- exports/`exports-package$package`.Encoder#
@@ -3516,7 +3510,7 @@ Uri => i9727.scala
35163510
Text => empty
35173511
Language => Scala
35183512
Symbols => 7 entries
3519-
Occurrences => 12 entries
3513+
Occurrences => 11 entries
35203514

35213515
Symbols:
35223516
i9727/Test# => class Test
@@ -3533,7 +3527,6 @@ Occurrences:
35333527
[2:10..2:10): <- i9727/Test#`<init>`().
35343528
[2:11..2:12): a <- i9727/Test#a.
35353529
[2:14..2:17): Int -> scala/Int#
3536-
[3:0..3:0): <- i9727/i9727$package.
35373530
[3:4..3:5): a <- i9727/i9727$package.a.
35383531
[3:12..3:16): Test -> i9727/Test#
35393532
[3:16..3:16): -> i9727/Test#`<init>`().
@@ -4381,8 +4374,8 @@ Schema => SemanticDB v4
43814374
Uri => toplevel.scala
43824375
Text => empty
43834376
Language => Scala
4384-
Symbols => 18 entries
4385-
Occurrences => 42 entries
4377+
Symbols => 19 entries
4378+
Occurrences => 44 entries
43864379

43874380
Symbols:
43884381
_empty_/MyProgram# => final class MyProgram
@@ -4402,10 +4395,10 @@ _empty_/toplevel$package.combine(+1).(y) => param y
44024395
_empty_/toplevel$package.combine(+1).(z) => param z
44034396
_empty_/toplevel$package.combine(+2). => method combine
44044397
_empty_/toplevel$package.foo(). => method foo
4398+
_empty_/toplevel$package.fooRef(). => method fooRef
44054399
local0 => val local error
44064400

44074401
Occurrences:
4408-
[0:0..0:0): <- _empty_/toplevel$package.
44094402
[0:11..0:12): a <- _empty_/toplevel$package.a.
44104403
[1:11..1:12): x <- _empty_/toplevel$package.combine().(x)
44114404
[1:14..1:17): Int -> scala/Int#
@@ -4447,4 +4440,7 @@ Occurrences:
44474440
[5:46..5:51): times -> _empty_/toplevel$package.MyProgram().(times)
44484441
[5:53..5:60): foreach -> scala/collection/immutable/Range#foreach().
44494442
[5:67..5:74): println -> scala/Predef.println(+1).
4443+
[6:4..6:10): fooRef <- _empty_/toplevel$package.fooRef().
4444+
[6:13..6:29): toplevel$package -> _empty_/toplevel$package.
4445+
[6:30..6:33): foo -> _empty_/toplevel$package.foo().
44504446

0 commit comments

Comments
 (0)