Skip to content

Commit bfa32a4

Browse files
authored
Change Show Tuple2 instance to generic tuple (#16093)
2 parents fde2189 + 27ae720 commit bfa32a4

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ object Formatting {
5858
def show(x: Seq[X]) = new CtxShow:
5959
def run(using Context) = x.map(show1)
6060

61-
given [A: Show, B: Show]: Show[(A, B)] with
62-
def show(x: (A, B)) = new CtxShow:
63-
def run(using Context) = (show1(x._1), show1(x._2))
61+
given [H: Show, T <: Tuple: Show]: Show[H *: T] with
62+
def show(x: H *: T) = new CtxShow:
63+
def run(using Context) = show1(x.head) *: Show[T].show(x.tail).ctxShow.asInstanceOf[Tuple]
6464

6565
given [X: Show]: Show[X | Null] with
6666
def show(x: X | Null) = if x == null then "null" else Show[X].show(x.nn)

compiler/test/dotty/tools/dotc/StringFormatterTest.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class StringFormatterTest extends AbstractStringFormatterTest:
2222
@Test def flagsSeq = check("<static>, final", i"${Seq(JavaStatic, Final)}%, %")
2323
@Test def flagsTup = check("(<static>,final)", i"${(JavaStatic, Final)}")
2424
@Test def seqOfTup2 = check("(final,given), (private,lazy)", i"${Seq((Final, Given), (Private, Lazy))}%, %")
25+
@Test def seqOfTup3 = check("(Foo,given, (right is approximated))", i"${Seq((Foo, Given, TypeComparer.ApproxState.None.addHigh))}%, %")
2526

2627
class StorePrinter extends Printer:
2728
var string: String = "<never set>"
@@ -76,6 +77,11 @@ class ExStringFormatterTest extends AbstractStringFormatterTest:
7677
|where: Foo is a type
7778
| Foo² is a type
7879
|""".stripMargin, ex"${(Foo, Foo)}")
80+
@Test def seqOfTup3Amb = check("""[(Foo,Foo²,<nonsensical>type Err</nonsensical>)]
81+
|
82+
|where: Foo is a type
83+
| Foo² is a type
84+
|""".stripMargin, ex"${Seq((Foo, Foo, Err))}")
7985
end ExStringFormatterTest
8086

8187
abstract class AbstractStringFormatterTest extends DottyTest:

0 commit comments

Comments
 (0)