Skip to content

Commit 11c3afa

Browse files
committed
improvement: Don't dealias named tuples for type hints
This causes the code to grow quite a lot. Fixes scalameta/metals#7397
1 parent 2d034c2 commit 11c3afa

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ object MetalsInteractive:
206206
// Handle select on named tuples
207207
case (Apply(Apply(TypeApply(fun, List(t1, t2)), List(ddef)), List(Literal(Constant(i: Int))))) :: _
208208
if fun.symbol.exists && fun.symbol.name == nme.apply &&
209-
fun.symbol.owner.exists && fun.symbol.owner == getModuleIfDefined("scala.NamedTuple").moduleClass =>
209+
fun.symbol.owner.exists && fun.symbol.owner == defn.NamedTupleModule.moduleClass =>
210210
def getIndex(t: Tree): Option[Type] =
211211
t.tpe.dealias match
212212
case AppliedType(_, args) => args.get(i)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class PcInlayHintsProvider(
142142
if isInScope(tpe) then tpe
143143
else tpe.deepDealias(using indexedCtx.ctx)
144144

145-
val dealiased = optDealias(tpe)
145+
val dealiased = if tpe.isNamedTupleType then tpe else optDealias(tpe)
146146
val tpeStr = printer.tpe(dealiased)
147147
val usedRenames = printer.getUsedRenames
148148
val parts = partsFromType(dealiased, usedRenames)

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

+20
Original file line numberDiff line numberDiff line change
@@ -1055,4 +1055,24 @@ class InlayHintsSuite extends BaseInlayHintsSuite {
10551055
|}
10561056
|""".stripMargin
10571057
)
1058+
1059+
@Test def `named-tuples` =
1060+
check(
1061+
"""|def hello = (path = ".", num = 5)
1062+
|
1063+
|def test =
1064+
| hello ++ (line = 1)
1065+
|
1066+
|@main def bla =
1067+
| val x: (path: String, num: Int, line: Int) = test
1068+
|""".stripMargin,
1069+
"""|def hello/*: (path : String<<java/lang/String#>>, num : Int<<scala/Int#>>)*/ = (path = ".", num = 5)/*[(String<<java/lang/String#>>, Int<<scala/Int#>>)]*/
1070+
|
1071+
|def test/*: Concat<<scala/NamedTuple.Concat#>>[(path : String<<java/lang/String#>>, num : Int<<scala/Int#>>), (line : Int<<scala/Int#>>)]*/ =
1072+
| hello ++/*[Tuple1<<scala/Tuple1#>>["line"], Tuple1<<scala/Tuple1#>>[Int<<scala/Int#>>]]*/ (line = 1)/*(using refl<<scala/`<:<`.refl().>>)*//*[Tuple1<<scala/Tuple1#>>[Int<<scala/Int#>>]]*/
1073+
|
1074+
|@main def bla/*: Unit<<scala/Unit#>>*/ =
1075+
| val x: (path: String, num: Int, line: Int) = test
1076+
|""".stripMargin
1077+
)
10581078
}

0 commit comments

Comments
 (0)