Skip to content

Commit 9943ade

Browse files
committed
avoid generating init symbol for objects
1 parent a63dde5 commit 9943ade

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

semanticdb/input/src/main/scala/example/Classes.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package example
2-
2+
/*
33
class C1(val x1: Int) extends AnyVal
44
55
class C2(val x2: Int) extends AnyVal
@@ -13,9 +13,9 @@ object C4
1313
object M {
1414
implicit class C5(x: Int)
1515
}
16-
16+
*/
1717
case class C6(private val x: Int)
18-
18+
/*
1919
class C7(x: Int)
2020
2121
class C8(private[this] val x: Int)
@@ -31,3 +31,4 @@ object N {
3131
local + 2
3232
}
3333
}
34+
*/

semanticdb/src/dotty/semanticdb/SemanticdbConsumer.scala

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,16 @@ class SemanticdbConsumer extends TastyConsumer {
124124
symbol.name == "<init>"
125125

126126
def isSyntheticConstructor(implicit ctx: Context): Boolean = {
127+
val isObjectConstructor = symbol.isConstructor && symbol.owner != NoSymbol && symbol.owner.flags.is(Flags.Object)
128+
//println("====>", symbol, symbol.owner, symbol.owner.flags, symbol.owner.flags.isObject, isObjectConstructor)
127129
val isModuleConstructor = symbol.isConstructor && symbol.owner.isClass
128130
val isTraitConstructor = symbol.isConstructor && symbol.owner.isTrait
129131
val isInterfaceConstructor = symbol.isConstructor && symbol.owner.flags.is(Flags.JavaDefined) && symbol.owner.isTrait
130132
val isEnumConstructor = symbol.isConstructor && symbol.owner.flags.is(Flags.JavaDefined) && symbol.owner.flags.is(Flags.Enum)
131133
/*val isStaticConstructor = symbol.name == g.TermName("<clinit>")*/
132134
//val isClassfileAnnotationConstructor = symbol.owner.isClassfileAnnotation
133135
/*isModuleConstructor || */
134-
isTraitConstructor || isInterfaceConstructor ||
136+
isTraitConstructor || isInterfaceConstructor || isObjectConstructor ||
135137
isEnumConstructor /*|| isStaticConstructor || isClassfileAnnotationConstructor*/
136138
}
137139
def isLocalChild(implicit ctx: Context): Boolean =
@@ -289,9 +291,8 @@ class SemanticdbConsumer extends TastyConsumer {
289291
/* When we consider snipper of the form: `abstract class DepAdvD[CC[X[C] <: B], X[Z], C] extends DepTemp`,
290292
The symbol for C will be something like example/DepAdvD#`<init>`().[CC].[X].[C].
291293
This is illogic: a init method can't have any child. Thus, when the current symbol is
292-
a typeparameter (or anything, but here it is just implemented for type parameter), and the owner
293-
is an init, we can just "jump" over the init. */
294-
if (symbol.isTypeParameter && symbol.owner.name == "<init>")
294+
a typeparameter (or anything), and the owner is an init, we can just "jump" over the init. */
295+
if (symbol.owner.name == "<init>")
295296
iterateParent(symbol.owner.owner)
296297
else
297298
iterateParent(symbol.owner)
@@ -343,8 +344,8 @@ class SemanticdbConsumer extends TastyConsumer {
343344
(iterateParent(symbol), true)
344345
}
345346

346-
println(symbol_path, range)
347347
if (symbol_path == "" || symbol.isUselessOccurrence) return
348+
println(symbol_path, range, symbol.owner.flags)
348349

349350
val key = (symbol_path, range)
350351
if (!is_global || !(symbolPathsMap.contains(key))) {
@@ -509,8 +510,8 @@ class SemanticdbConsumer extends TastyConsumer {
509510
addOccurenceTree(tree,
510511
s.SymbolOccurrence.Role.DEFINITION,
511512
range(tree, tree.symbol.pos, tree.symbol.name))
512-
println("constr symbol pos: ", constr.symbol.pos.startColumn, constr.symbol.pos.endColumn)
513-
println("constr pos: ", constr.pos.startColumn, constr.pos.endColumn)
513+
//println("constr symbol pos: ", constr.symbol.pos.startColumn, constr.symbol.pos.endColumn)
514+
//println("constr pos: ", constr.pos.startColumn, constr.pos.endColumn)
514515
// then the constructor
515516
if (!constr.isUserCreated) {
516517
fittedInitClassRange = Some(
@@ -575,8 +576,9 @@ class SemanticdbConsumer extends TastyConsumer {
575576
}
576577
if (tree.symbol.name != "<none>") {
577578
val range_symbol = range(tree, tree.symbol.pos, tree.symbol.name)
578-
if (tree.symbol.name == "<init>" && tree.symbol.flags.is(Flags.Object)) {
579-
579+
//println(tree, tree.symbol.name, tree.symbol.owner, tree.symbol.owner.flags)
580+
if (tree.symbol.name == "<init>" && tree.symbol.owner != NoSymbol && tree.symbol.owner.flags.is(Flags.Object)) {
581+
//println("omitting", tree.symbol.name)
580582
} else if (tree.symbol.name == "<init>" && fittedInitClassRange != None) {
581583
addOccurenceTree(tree,
582584
s.SymbolOccurrence.Role.DEFINITION,
@@ -604,7 +606,7 @@ class SemanticdbConsumer extends TastyConsumer {
604606
addOccurenceTree(tree,
605607
s.SymbolOccurrence.Role.REFERENCE,
606608
range,
607-
false)
609+
true)
608610
super.traverseTree(tree)
609611
}
610612

semanticdb/test/dotty/semanticdb/Tests.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class Tests {
178178
//@Test def testAccess(): Unit = checkFile("example/Access.scala")
179179
//@Test def testAdvanced(): Unit = checkFile("example/Advanced.scala")
180180
//@Test def testAnonymous(): Unit = checkFile("example/Anonymous.scala")
181-
//@Test def testClasses(): Unit = checkFile("example/Classes.scala")
181+
@Test def testClasses(): Unit = checkFile("example/Classes.scala")
182182
//@Test def testEmpty(): Unit = checkFile("example/Empty.scala")
183183
//@Test def testEmptyObject(): Unit = checkFile("example/EmptyObject.scala")
184184
//@Test def testExample(): Unit = checkFile("example/Example.scala")
@@ -190,18 +190,18 @@ class Tests {
190190
//@Test def testLocalFile(): Unit = checkFile("example/local-file.scala")
191191
//@Test def testLocals(): Unit = checkFile("example/Locals.scala")
192192
//@Test def testMacroAnnotations(): Unit = checkFile("example/MacroAnnotations.scala")
193-
//WIP @Test def testMethods(): Unit = checkFile("example/Methods.scala")
193+
//WIP(assert) @Test def testMethods(): Unit = checkFile("example/Methods.scala")
194194
//@Test def testMultiArguments(): Unit = checkFile("example/MultiArguments.scala")
195195
//@Test def testMethodUsages(): Unit = checkFile("example/MethodUsages.scala")
196-
//@Test def testObjects(): Unit = checkFile("example/Objects.scala")
196+
//def testObjects(): Unit = checkFile("example/Objects.scala")
197197
//@Test def testOverrides(): Unit = checkFile("example/Overrides.scala")
198198
//WIP @Test def testPrefixes(): Unit = checkFile("example/Prefixes.scala")
199199
//@Test def testSelfs(): Unit = checkFile("example/Selfs.scala")
200200
//WIP @Test def testSynthetic(): Unit = checkFile("example/Synthetic.scala")
201201
//WIP @Test def testTraits(): Unit = checkFile("example/Traits.scala")
202202
//WIP @Test def testTypes(): Unit = checkFile("example/Types.scala")
203203
//@Test def testVals(): Unit = checkFile("example/Vals.scala")
204-
@Test def testDependantModule(): Unit = checkFile("example/DependantModule.scala")
204+
//@Test def testDependantModule(): Unit = checkFile("example/DependantModule.scala")
205205
//@Test def testNew(): Unit = checkFile("example/New.scala")
206206
//@Test def testIgnoredSymbol(): Unit = checkFile("example/IgnoredSymbol.scala")
207207

0 commit comments

Comments
 (0)