Skip to content

Commit 6c2f6f5

Browse files
authored
Fix incorrect XRay hint (#24738)
Fixes scalameta/metals#8021
1 parent 182c282 commit 6c2f6f5

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,15 +529,18 @@ object XRayModeHint:
529529
case apply @ Apply(inner, _)
530530
if !apply.span.isZeroExtent && inner.sourcePos.exists && !isParentOnSameLine &&
531531
!isParentApply && endsInSimpleSelect(apply) && isEndOfLine(tree.sourcePos) =>
532-
Some((apply.tpe.widen.deepDealiasAndSimplify, tree.sourcePos))
532+
Some((apply.tpe.widen.finalResultType.deepDealiasAndSimplify, tree.sourcePos))
533533
/*
534534
innerTree
535535
.select
536536
*/
537537
case select @ Select(innerTree, _)
538538
if !select.span.isZeroExtent && innerTree.sourcePos.exists &&
539539
!isParentOnSameLine && !isParentApply && isEndOfLine(tree.sourcePos) =>
540-
Some((select.tpe.widen.deepDealiasAndSimplify, tree.sourcePos))
540+
val tpe = parent match
541+
case Some(ta: TypeApply) => ta.tpe
542+
case _ => select.tpe
543+
Some((tpe.widen.finalResultType.deepDealiasAndSimplify, tree.sourcePos))
541544
case _ => None
542545
else None
543546

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1687,4 +1687,40 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
16871687
|}
16881688
|""".stripMargin
16891689
)
1690+
1691+
@Test def `xray-metals-i8021` =
1692+
check(
1693+
"""|object Main:
1694+
|
1695+
| case class Order(id: String, amount: BigDecimal)
1696+
| case class User(name: String, orders: List[Order])
1697+
|
1698+
| val users = List(
1699+
| User("Alice", List(Order("A1", 100), Order("A2", 50))),
1700+
| User("Bob", List(Order("B1", 200)))
1701+
| )
1702+
|
1703+
| val total = users
1704+
| .filter(_.name.startsWith("A"))
1705+
| .flatMap(_.orders)
1706+
| .map(_.amount)
1707+
| .sum
1708+
|""".stripMargin,
1709+
"""|object Main:
1710+
|
1711+
| case class Order(id: String, amount: BigDecimal)
1712+
| case class User(name: String, orders: List[Order])
1713+
|
1714+
| val users/*: List<<scala/collection/immutable/List#>>[User<<(4:13)>>]*/ = List/*[User<<(4:13)>>]*/(
1715+
| /*elems = */User(/*name = */"Alice", /*orders = */List/*[Order<<(3:13)>>]*/(/*elems = */Order(/*id = */"A1", /*int2bigDecimal<<scala/math/BigDecimal.int2bigDecimal().>>(*//*amount = */100/*)*/), Order(/*id = */"A2", /*int2bigDecimal<<scala/math/BigDecimal.int2bigDecimal().>>(*//*amount = */50/*)*/))),
1716+
| User(/*name = */"Bob", /*orders = */List/*[Order<<(3:13)>>]*/(/*elems = */Order(/*id = */"B1", /*int2bigDecimal<<scala/math/BigDecimal.int2bigDecimal().>>(*//*amount = */200/*)*/)))
1717+
| )
1718+
|
1719+
| val total/*: BigDecimal<<scala/math/BigDecimal#>>*/ = users
1720+
| .filter(/*p = */_.name.startsWith("A"))/*: List<<scala/collection/immutable/List#>>[User<<(4:13)>>]*/
1721+
| .flatMap/*[Order<<(3:13)>>]*/(/*f = */_.orders)/* : List<<scala/collection/immutable/List#>>[Order<<(3:13)>>]*/
1722+
| .map/*[BigDecimal<<scala/math/BigDecimal#>>]*/(/*f = */_.amount)/* : List<<scala/collection/immutable/List#>>[BigDecimal<<scala/math/BigDecimal#>>]*/
1723+
| .sum/*[BigDecimal<<scala/math/BigDecimal#>>]*//*(using BigDecimalIsFractional<<scala/math/Numeric.BigDecimalIsFractional.>>)*//* : BigDecimal<<scala/math/BigDecimal#>>*/
1724+
|""".stripMargin
1725+
)
16901726
}

0 commit comments

Comments
 (0)