Skip to content

Commit 4042f9f

Browse files
dwijnandWojciechMazur
authored andcommitted
Par back sourceSymbol usage, to keep some non-source
Given: class Foo(name: String, age: Int) case class Person(name: String) Is the Foo constructor symbol synthetic? Being the primary constructor, sourceSymbol considers it should be substituted for the Foo class symbol. Similarly, the Person apply method symbol is replaced by the class symbol for Person (via the Person module class). Doing so leads the presentation compiler to show details about the class, rather than the constructor or the apply method intially targeted. [Cherry-picked 6792fc7]
1 parent 0520f5a commit 4042f9f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ object Symbols extends SymUtils {
305305

306306
/** A symbol related to `sym` that is defined in source code.
307307
*
308-
* @see enclosingSourceSymbols
308+
* @see [[interactive.Interactive.enclosingSourceSymbols]]
309309
*/
310310
@annotation.tailrec final def sourceSymbol(using Context): Symbol =
311311
if (!denot.exists)

presentation-compiler/src/main/dotty/tools/pc/MetalsInteractive.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,14 @@ object MetalsInteractive:
229229
end if
230230
case Nil => Nil
231231
end go
232-
go(path).map((sym, tp) => (sym.sourceSymbol, tp))
232+
go(path).map { (sym, tp) =>
233+
if sym.is(Synthetic) && sym.name == StdNames.nme.apply then
234+
(sym, tp) // return synthetic apply, rather than the apply's owner
235+
else if sym.isClassConstructor && sym.isPrimaryConstructor then
236+
(sym, tp) // return the class constructor, rather than the class (so skip trait constructors)
237+
else
238+
(sym.sourceSymbol, tp)
239+
}
233240
end enclosingSymbolsWithExpressionType
234241

235242
import dotty.tools.pc.utils.MtagsEnrichments.*

0 commit comments

Comments
 (0)