Skip to content

Commit c15e01e

Browse files
committed
handle inlined tree in implicit parameter inlay hints
1 parent c82b623 commit c15e01e

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,18 @@ object ImplicitParameters:
277277
def unapply(tree: Tree)(using params: InlayHintsParams, ctx: Context) =
278278
if (params.implicitParameters()) {
279279
tree match
280-
case Apply(fun, args)
281-
if args.exists(isSyntheticArg) && !tree.sourcePos.span.isZeroExtent && !args.exists(isQuotes(_)) =>
282-
val (implicitArgs, providedArgs) = args.partition(isSyntheticArg)
283-
val pos = implicitArgs.head.sourcePos
284-
Some(implicitArgs, pos)
280+
case Apply(_, args) if hasImplicitArgs(tree, args) => implicitArgs(args)
281+
case Inlined(Apply(_, args), _, _) if hasImplicitArgs(tree, args) => implicitArgs(args)
285282
case _ => None
286283
} else None
287284

285+
private def hasImplicitArgs(tree: Tree, args: List[Tree])(using Context): Boolean =
286+
args.exists(isSyntheticArg) && !tree.sourcePos.span.isZeroExtent && !args.exists(isQuotes)
287+
288+
private def implicitArgs(args: List[Tree])(using Context): Option[(List[Tree], SourcePosition)] =
289+
val found = args.filter(isSyntheticArg)
290+
Option.when(found.nonEmpty)(found, found.head.sourcePos)
291+
288292
@tailrec
289293
def isSyntheticArg(tree: Tree)(using Context): Boolean = tree match
290294
case tree: Ident =>

presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,4 +1723,38 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
17231723
| .sum/*[BigDecimal<<scala/math/BigDecimal#>>]*//*(using BigDecimalIsFractional<<scala/math/Numeric.BigDecimalIsFractional.>>)*//* : BigDecimal<<scala/math/BigDecimal#>>*/
17241724
|""".stripMargin
17251725
)
1726+
1727+
@Test def `inline-def-implicit-param` =
1728+
check(
1729+
"""|trait Codec[T]
1730+
|object Main {
1731+
| given intCodec: Codec[Int] = ???
1732+
| val x = summon[Codec[Int]]
1733+
|}
1734+
|""".stripMargin,
1735+
"""|trait Codec[T]
1736+
|object Main {
1737+
| given intCodec: Codec[Int] = ???
1738+
| val x/*: Codec<<(1:6)>>[Int<<scala/Int#>>]*/ = summon[Codec[Int]]/*(using intCodec<<(3:8)>>)*/
1739+
|}
1740+
|""".stripMargin
1741+
)
1742+
1743+
@Test def `inline-def-implicit-param-vs-implicitly` =
1744+
check(
1745+
"""|trait Codec[T]
1746+
|object Main {
1747+
| implicit val intCodec: Codec[Int] = ???
1748+
| val x = implicitly[Codec[Int]]
1749+
| val y = summon[Codec[Int]]
1750+
|}
1751+
|""".stripMargin,
1752+
"""|trait Codec[T]
1753+
|object Main {
1754+
| implicit val intCodec: Codec[Int] = ???
1755+
| val x/*: Codec<<(1:6)>>[Int<<scala/Int#>>]*/ = implicitly[Codec[Int]]/*(using intCodec<<(3:15)>>)*/
1756+
| val y/*: Codec<<(1:6)>>[Int<<scala/Int#>>]*/ = summon[Codec[Int]]/*(using intCodec<<(3:15)>>)*/
1757+
|}
1758+
|""".stripMargin
1759+
)
17261760
}

0 commit comments

Comments
 (0)