Skip to content

Commit 09b389b

Browse files
committed
Change trytoShow's to not use raw string
1 parent 0df5ae2 commit 09b389b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

compiler/src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,7 @@ object Decorators {
280280
case ex: CyclicReference => "... (caught cyclic reference) ..."
281281
case NonFatal(ex)
282282
if !ctx.mode.is(Mode.PrintShowExceptions) && !ctx.settings.YshowPrintErrors.value =>
283-
val msg = ex match
284-
case te: TypeError => te.toMessage.message
285-
case _ => ex.getMessage
286-
s"[cannot display due to $msg, raw string = $x]"
283+
s"... (cannot display due to ${ex.className} ${ex.getMessage}) ..."
287284
case _ => String.valueOf(x).nn
288285

289286
/** Returns the simple class name of `x`. */
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package dotty.tools
2+
package dotc
3+
package core
4+
5+
import Contexts.*, Decorators.*, Denotations.*, SymDenotations.*, Symbols.*, Types.*
6+
import printing.Formatting.Show
7+
8+
import org.junit.Test
9+
import org.junit.Assert.*
10+
11+
class ShowDecoratorTest extends DottyTest:
12+
import ShowDecoratorTest.*
13+
14+
@Test def t1 = assertEquals("... (cannot display due to FooException boom) ...", Foo().tryToShow)
15+
end ShowDecoratorTest
16+
17+
object ShowDecoratorTest:
18+
import printing.*, Texts.*
19+
class FooException extends Exception("boom")
20+
case class Foo() extends Showable:
21+
def toText(printer: Printer): Text = throw new FooException

0 commit comments

Comments
 (0)