Skip to content

Commit edd392e

Browse files
committed
Exclude synthesized parseArgument(given_FromString_Int) by @main
By checking if the template's owner module symbol has an Invisible flag.
1 parent 560fc18 commit edd392e

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ class ExtractSemanticDB extends Phase:
180180
registerUseGuarded(None, privateWithin, spanOfSymbol(privateWithin, tree.span, tree.source), tree.source)
181181
else if !excludeSymbol(tree.symbol) then
182182
registerSymbol(tree.symbol, symbolKinds(tree))
183+
case tree: Template if tree.symbol.owner.is(Invisible) =>
184+
// do nothing
185+
// exclude the symbols and synthetics generated by @main annotation
186+
// (main class generated by @main has `Invisible` flag, see `MainProxies.scala`).
183187
case tree: Template =>
184188
val ctorSym = tree.constr.symbol
185189
for parent <- tree.parentsOrDerived if parent.span.hasLength do

tests/semanticdb/expect/toplevel.expect.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ def combine/*<-_empty_::toplevel$package.combine(+1).*/(x/*<-_empty_::toplevel$p
44
def combine/*<-_empty_::toplevel$package.combine(+2).*/ = 0
55
def foo/*<-_empty_::toplevel$package.foo().*/ = "foo"
66
@main/*->scala::main#*/ def MyProgram/*<-_empty_::toplevel$package.MyProgram().*/(times/*<-_empty_::toplevel$package.MyProgram().(times)*/: Int/*->scala::Int#*/): Unit/*->scala::Unit#*/ = (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+
@main/*->scala::main#*/ def readInts/*<-_empty_::toplevel$package.readInts().*/(ints/*<-_empty_::toplevel$package.readInts().(ints)*/: Int/*->scala::Int#*/*): Unit/*->scala::Unit#*/ = println/*->scala::Predef.println(+1).*/(ints/*->_empty_::toplevel$package.readInts().(ints)*/.mkString/*->scala::collection::IterableOnceOps#mkString(+1).*/(","))
78
def fooRef/*<-_empty_::toplevel$package.fooRef().*/ = 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,4 +4,5 @@ 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+
@main def readInts(ints: Int*): Unit = println(ints.mkString(","))
78
def fooRef = toplevel$package.foo

tests/semanticdb/metac.expect

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4607,16 +4607,14 @@ Schema => SemanticDB v4
46074607
Uri => toplevel.scala
46084608
Text => empty
46094609
Language => Scala
4610-
Symbols => 19 entries
4611-
Occurrences => 34 entries
4612-
Synthetics => 2 entries
4610+
Symbols => 18 entries
4611+
Occurrences => 42 entries
4612+
Synthetics => 1 entries
46134613

46144614
Symbols:
46154615
_empty_/MyProgram# => final class MyProgram extends Object { self: MyProgram => +2 decls }
4616-
_empty_/MyProgram#`<init>`(). => primary ctor <init> (): MyProgram
4617-
_empty_/MyProgram#main(). => static method main (param args: Array[String]): Unit
4618-
_empty_/MyProgram#main().(args) => param args: Array[String]
4619-
_empty_/toplevel$package. => final package object _empty_ extends Object { self: _empty_.type => +8 decls }
4616+
_empty_/readInts# => final class readInts extends Object { self: readInts => +2 decls }
4617+
_empty_/toplevel$package. => final package object _empty_ extends Object { self: _empty_.type => +9 decls }
46204618
_empty_/toplevel$package.MyProgram(). => method MyProgram (param times: Int): Unit
46214619
_empty_/toplevel$package.MyProgram().(times) => param times: Int
46224620
_empty_/toplevel$package.a. => val inline method a ""
@@ -4630,7 +4628,8 @@ _empty_/toplevel$package.combine(+1).(z) => param z: Int
46304628
_empty_/toplevel$package.combine(+2). => method combine => Int
46314629
_empty_/toplevel$package.foo(). => method foo => String
46324630
_empty_/toplevel$package.fooRef(). => method fooRef => String
4633-
local0 => val local error: ParseError
4631+
_empty_/toplevel$package.readInts(). => method readInts (param ints: Int*): Unit
4632+
_empty_/toplevel$package.readInts().(ints) => param ints: Int*
46344633

46354634
Occurrences:
46364635
[0:11..0:12): a <- _empty_/toplevel$package.a.
@@ -4665,10 +4664,17 @@ Occurrences:
46654664
[5:46..5:51): times -> _empty_/toplevel$package.MyProgram().(times)
46664665
[5:53..5:60): foreach -> scala/collection/immutable/Range#foreach().
46674666
[5:67..5:74): println -> scala/Predef.println(+1).
4668-
[6:4..6:10): fooRef <- _empty_/toplevel$package.fooRef().
4669-
[6:30..6:33): foo -> _empty_/toplevel$package.foo().
4667+
[6:1..6:5): main -> scala/main#
4668+
[6:10..6:18): readInts <- _empty_/toplevel$package.readInts().
4669+
[6:19..6:23): ints <- _empty_/toplevel$package.readInts().(ints)
4670+
[6:25..6:28): Int -> scala/Int#
4671+
[6:32..6:36): Unit -> scala/Unit#
4672+
[6:39..6:46): println -> scala/Predef.println(+1).
4673+
[6:47..6:51): ints -> _empty_/toplevel$package.readInts().(ints)
4674+
[6:52..6:60): mkString -> scala/collection/IterableOnceOps#mkString(+1).
4675+
[7:4..7:10): fooRef <- _empty_/toplevel$package.fooRef().
4676+
[7:30..7:33): foo -> _empty_/toplevel$package.foo().
46704677

46714678
Synthetics:
4672-
[5:0..5:0): => *(given_FromString_Int)
46734679
[5:41..5:42):1 => intWrapper(*)
46744680

0 commit comments

Comments
 (0)