Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/printing/Formatting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ object Formatting {
def show(x: Seq[X]) = new CtxShow:
def run(using Context) = x.map(show1)

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

given [X: Show]: Show[X | Null] with
def show(x: X | Null) = if x == null then "null" else Show[X].show(x.nn)
Expand Down
6 changes: 6 additions & 0 deletions compiler/test/dotty/tools/dotc/StringFormatterTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class StringFormatterTest extends AbstractStringFormatterTest:
@Test def flagsSeq = check("<static>, final", i"${Seq(JavaStatic, Final)}%, %")
@Test def flagsTup = check("(<static>,final)", i"${(JavaStatic, Final)}")
@Test def seqOfTup2 = check("(final,given), (private,lazy)", i"${Seq((Final, Given), (Private, Lazy))}%, %")
@Test def seqOfTup3 = check("(Foo,given, (right is approximated))", i"${Seq((Foo, Given, TypeComparer.ApproxState.None.addHigh))}%, %")

class StorePrinter extends Printer:
var string: String = "<never set>"
Expand Down Expand Up @@ -76,6 +77,11 @@ class ExStringFormatterTest extends AbstractStringFormatterTest:
|where: Foo is a type
| Foo² is a type
|""".stripMargin, ex"${(Foo, Foo)}")
@Test def seqOfTup3Amb = check("""[(Foo,Foo²,<nonsensical>type Err</nonsensical>)]
|
|where: Foo is a type
| Foo² is a type
|""".stripMargin, ex"${Seq((Foo, Foo, Err))}")
end ExStringFormatterTest

abstract class AbstractStringFormatterTest extends DottyTest:
Expand Down