Skip to content

fix #8954 use tree source, look inside byname arguments #8971

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ class ExtractSemanticDB extends Phase:

override def traverse(tree: Tree)(using Context): Unit =

inline def traverseCtorParamTpt(ctorSym: Symbol, tpt: Tree): Unit =
val tptSym = tpt.symbol
def traverseCtorParamTpt(ctorSym: Symbol, tpt: Tree)(using Context): Unit =
val tptSym = tpt match
case ByNameTypeTree(tpt) => tpt.symbol
case tpt => tpt.symbol
if tptSym.owner == ctorSym
val found = matchingMemberType(tptSym, ctorSym.owner)
if tpt.span.hasLength
Expand All @@ -131,7 +133,7 @@ class ExtractSemanticDB extends Phase:
&& tree.pid.span.hasLength
tree.pid match
case tree @ Select(qual, name) =>
registerDefinition(tree.symbol, adjustSpanToName(tree.span, qual.span, name), Set.empty)
registerDefinition(tree.symbol, adjustSpanToName(tree.span, qual.span, name, tree.source), Set.empty)
traverse(qual)
case tree => registerDefinition(tree.symbol, tree.span, Set.empty)
tree.stats.foreach(traverse)
Expand Down Expand Up @@ -206,7 +208,7 @@ class ExtractSemanticDB extends Phase:
val lhs = tree.lhs.symbol
val setter = lhs.matchingSetter.orElse(lhs)
tree.lhs match
case tree @ Select(qual, name) => registerUse(setter, adjustSpanToName(tree.span, qual.span, name))
case tree @ Select(qual, name) => registerUse(setter, adjustSpanToName(tree.span, qual.span, name, tree.source))
case tree => registerUse(setter, tree.span)
traverseChildren(tree.lhs)
traverse(tree.rhs)
Expand All @@ -217,7 +219,7 @@ class ExtractSemanticDB extends Phase:
case tree: Select =>
val qualSpan = tree.qualifier.span
val sym = tree.symbol.adjustIfCtorTyparam
registerUseGuarded(tree.qualifier.symbol.ifExists, sym, adjustSpanToName(tree.span, qualSpan, tree.name))
registerUseGuarded(tree.qualifier.symbol.ifExists, sym, adjustSpanToName(tree.span, qualSpan, tree.name, tree.source))
if qualSpan.exists && qualSpan.hasLength then
traverse(tree.qualifier)
case tree: Import =>
Expand Down Expand Up @@ -502,7 +504,7 @@ class ExtractSemanticDB extends Phase:
}).toMap
end findGetters

private def adjustSpanToName(span: Span, qualSpan: Span, name: Name)(using Context) =
private def adjustSpanToName(span: Span, qualSpan: Span, name: Name, source: SourceFile) =
val end = span.end
val limit = qualSpan.end
val start =
Expand Down Expand Up @@ -559,8 +561,8 @@ class ExtractSemanticDB extends Phase:
case _ =>
symkinds.toSet

private inline def ctorParams(
vparamss: List[List[ValDef]], body: List[Tree])(traverseTpt: => Tree => Unit)(using Context): Unit =
private def ctorParams(
vparamss: List[List[ValDef]], body: List[Tree])(traverseTpt: Tree => Unit)(using Context): Unit =
@tu lazy val getters = findGetters(vparamss.flatMap(_.map(_.name)).toSet, body)
for
vparams <- vparamss
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CompilationTests extends ParallelTesting {
compileFilesInDir("tests/new", defaultOptions),
compileFilesInDir("tests/pos-scala2", scala2CompatMode),
compileFilesInDir("tests/pos-custom-args/erased", defaultOptions.and("-Yerased-terms")),
compileFilesInDir("tests/pos-custom-args/semanticdb", defaultOptions.and("-Ysemanticdb")),
compileFilesInDir("tests/pos", defaultOptions),
compileFilesInDir("tests/pos-deep-subtype", allowDeepSubtypes),
compileFile(
Expand Down
3 changes: 3 additions & 0 deletions tests/pos-custom-args/semanticdb/ctorByName.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Macro {
class StringContextOps(sc: => StringContext)
}
5 changes: 5 additions & 0 deletions tests/pos-custom-args/semanticdb/macro-pos/example_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import quoted._

object CodeImpl {
def codeExpr(using qctx: QuoteContext): Expr[String] = '{""}
}
10 changes: 10 additions & 0 deletions tests/pos-custom-args/semanticdb/macro-pos/example_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import quoted._

object TestImpl {
transparent inline def fun (inline arg: String): String =
/*
Pad out the file
Lorem ipsum dolor sit amet consectetur adipiscing elit tincidunt id augue, facilisi dignissim nibh litora lectus quam senectus fringilla molestie sollicitudin, nunc ullamcorper auctor turpis integer netus fermentum mattis magna. Nullam potenti diam tellus bibendum odio tristique felis, pharetra posuere at imperdiet suspendisse aenean, eu lobortis sapien eleifend aptent sociosqu.
*/
${ CodeImpl.codeExpr }
}
5 changes: 5 additions & 0 deletions tests/pos-custom-args/semanticdb/macro-pos/example_3.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Test {

def test = TestImpl.fun("")

}