From 0dad1c5bb12e4852ff5e418ebe7d63f8dac88882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Zieli=C5=84ski?= Date: Fri, 12 Dec 2025 13:28:19 +0100 Subject: [PATCH] fix incorrect XRay hint --- .../dotty/tools/pc/PcInlayHintsProvider.scala | 7 ++-- .../pc/tests/inlayHints/InlayHintsSuite.scala | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala b/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala index fe46419fe577..46b9cf3f4e3b 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/PcInlayHintsProvider.scala @@ -529,7 +529,7 @@ object XRayModeHint: case apply @ Apply(inner, _) if !apply.span.isZeroExtent && inner.sourcePos.exists && !isParentOnSameLine && !isParentApply && endsInSimpleSelect(apply) && isEndOfLine(tree.sourcePos) => - Some((apply.tpe.widen.deepDealiasAndSimplify, tree.sourcePos)) + Some((apply.tpe.widen.finalResultType.deepDealiasAndSimplify, tree.sourcePos)) /* innerTree .select @@ -537,7 +537,10 @@ object XRayModeHint: case select @ Select(innerTree, _) if !select.span.isZeroExtent && innerTree.sourcePos.exists && !isParentOnSameLine && !isParentApply && isEndOfLine(tree.sourcePos) => - Some((select.tpe.widen.deepDealiasAndSimplify, tree.sourcePos)) + val tpe = parent match + case Some(ta: TypeApply) => ta.tpe + case _ => select.tpe + Some((tpe.widen.finalResultType.deepDealiasAndSimplify, tree.sourcePos)) case _ => None else None diff --git a/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala b/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala index 555287a96837..4f5a593c10e4 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/inlayHints/InlayHintsSuite.scala @@ -1687,4 +1687,40 @@ class InlayHintsSuite extends BaseInlayHintsSuite { |} |""".stripMargin ) + + @Test def `xray-metals-i8021` = + check( + """|object Main: + | + | case class Order(id: String, amount: BigDecimal) + | case class User(name: String, orders: List[Order]) + | + | val users = List( + | User("Alice", List(Order("A1", 100), Order("A2", 50))), + | User("Bob", List(Order("B1", 200))) + | ) + | + | val total = users + | .filter(_.name.startsWith("A")) + | .flatMap(_.orders) + | .map(_.amount) + | .sum + |""".stripMargin, + """|object Main: + | + | case class Order(id: String, amount: BigDecimal) + | case class User(name: String, orders: List[Order]) + | + | val users/*: List<>[User<<(4:13)>>]*/ = List/*[User<<(4:13)>>]*/( + | /*elems = */User(/*name = */"Alice", /*orders = */List/*[Order<<(3:13)>>]*/(/*elems = */Order(/*id = */"A1", /*int2bigDecimal<>(*//*amount = */100/*)*/), Order(/*id = */"A2", /*int2bigDecimal<>(*//*amount = */50/*)*/))), + | User(/*name = */"Bob", /*orders = */List/*[Order<<(3:13)>>]*/(/*elems = */Order(/*id = */"B1", /*int2bigDecimal<>(*//*amount = */200/*)*/))) + | ) + | + | val total/*: BigDecimal<>*/ = users + | .filter(/*p = */_.name.startsWith("A"))/*: List<>[User<<(4:13)>>]*/ + | .flatMap/*[Order<<(3:13)>>]*/(/*f = */_.orders)/* : List<>[Order<<(3:13)>>]*/ + | .map/*[BigDecimal<>]*/(/*f = */_.amount)/* : List<>[BigDecimal<>]*/ + | .sum/*[BigDecimal<>]*//*(using BigDecimalIsFractional<>)*//* : BigDecimal<>*/ + |""".stripMargin + ) }