diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index 6bf763416406..c8165fb97c6f 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -147,7 +147,7 @@ class PlainPrinter(_ctx: Context) extends Printer { case tp: TypeParamRef => ParamRefNameString(tp) ~ lambdaHash(tp.binder) case tp: SingletonType => - toTextLocal(tp.underlying) ~ "(" ~ toTextRef(tp) ~ ")" + toTextSingleton(tp) case AppliedType(tycon, args) => (toTextLocal(tycon) ~ "[" ~ argsText(args) ~ "]").close case tp: RefinedType => @@ -226,6 +226,9 @@ class PlainPrinter(_ctx: Context) extends Printer { } }.close + def toTextSingleton(tp: SingletonType): Text = + toTextLocal(tp.underlying) ~ "(" ~ toTextRef(tp) ~ ")" + protected def paramsText(tp: LambdaType): Text = { def paramText(name: Name, tp: Type) = toText(name) ~ toTextRHS(tp) Text((tp.paramNames, tp.paramInfos).zipped.map(paramText), ", ") diff --git a/compiler/src/dotty/tools/dotc/printing/ReplPrinter.scala b/compiler/src/dotty/tools/dotc/printing/ReplPrinter.scala index 526e32fd07e8..72edf40ab112 100644 --- a/compiler/src/dotty/tools/dotc/printing/ReplPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/ReplPrinter.scala @@ -7,28 +7,33 @@ import dotty.tools.dotc.core.Flags._ import dotty.tools.dotc.core.NameOps._ import dotty.tools.dotc.core.Names.Name import dotty.tools.dotc.core.Symbols._ -import dotty.tools.dotc.core.Types.ExprType +import dotty.tools.dotc.core.Types._ import dotty.tools.dotc.printing.Texts._ class ReplPrinter(_ctx: Context) extends DecompilerPrinter(_ctx) { + val debugPrint = _ctx.settings.YprintDebug.value + override def nameString(name: Name): String = if (name.isReplAssignName) name.decode.toString.takeWhile(_ != '$') else super.nameString(name) override protected def exprToText(tp: ExprType): Text = - ": " ~ toText(tp.resType) + if (debugPrint) super.exprToText(tp) + else ": " ~ toText(tp.resType) override def toText(sym: Symbol): Text = if (sym.name.isReplAssignName) nameString(sym.name) + else if (debugPrint) super.toText(sym) else keyString(sym) ~~ nameString(sym.name.stripModuleClassSuffix) override def toText(const: Constant): Text = - if (const.tag == Constants.StringTag) Str('"' + const.value.toString + '"') + if (debugPrint) super.toText(const) + else if (const.tag == Constants.StringTag) Str('"' + const.value.toString + '"') else Str(const.value.toString) - override def dclText(sym: Symbol): Text = { + override def dclText(sym: Symbol): Text = if (debugPrint) super.dclText(sym) else { ("lazy": Text).provided(sym.is(Lazy)) ~~ toText(sym) ~ { if (sym.is(Method)) toText(sym.info) @@ -38,6 +43,15 @@ class ReplPrinter(_ctx: Context) extends DecompilerPrinter(_ctx) { } } + override def toTextSingleton(tp: SingletonType): Text = + if (debugPrint) + super.toTextSingleton(tp) + else + tp match { + case ConstantType(const) => toText(const) + case _ => toTextRef(tp) ~ ".type" + } + // We don't want the colors coming from RefinedPrinter as the REPL uses its // own syntax coloring mechanism. override def coloredStr(text: String, color: String): String = text diff --git a/compiler/test-resources/repl/defs b/compiler/test-resources/repl/defs index e538aed9b0a0..a42438dfc100 100644 --- a/compiler/test-resources/repl/defs +++ b/compiler/test-resources/repl/defs @@ -7,7 +7,7 @@ def baz(): Int scala> def qux(): Int = 2 def qux(): Int scala> def id(x: 4): 4 = x -def id(x: Int(4)): Int(4) +def id(x: 4): 4 scala> id(4) val res0: Int = 4 scala> def f given Int = 1 diff --git a/compiler/test-resources/repl/i5218 b/compiler/test-resources/repl/i5218 index eeca76c8635f..3402ed98e286 100644 --- a/compiler/test-resources/repl/i5218 +++ b/compiler/test-resources/repl/i5218 @@ -3,5 +3,4 @@ val tuple: (Int, String, Long) = (1,2,3) scala> 0.0 *: tuple val res0: (Double, Int, String, Long) = (0.0,1,2,3) scala> tuple ++ tuple -val res1: Int *: String *: Long *: - scala.Tuple.Concat[Unit, (Int, String, Long)(tuple)] = (1,2,3,1,2,3) +val res1: Int *: String *: Long *: scala.Tuple.Concat[Unit, tuple.type] = (1,2,3,1,2,3) \ No newline at end of file diff --git a/compiler/test-resources/type-printer/defs b/compiler/test-resources/type-printer/defs index 34b336f8a26a..f4f6514b1980 100644 --- a/compiler/test-resources/type-printer/defs +++ b/compiler/test-resources/type-printer/defs @@ -7,4 +7,4 @@ def baz[A](a: A): A scala> def qux[A](a: A): a.type = a def qux[A](a: A): a.type scala> def singleton: 1 = 1 -def singleton: Int(1) +def singleton: 1 diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index f1c41b54c55a..65f33caa106d 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -10,7 +10,7 @@ class ReplCompilerTests extends ReplTest { @Test def compileSingle = fromInitialState { implicit state => run("def foo: 1 = 1") - assertEquals("def foo: Int(1)", storedOutput().trim) + assertEquals("def foo: 1", storedOutput().trim) } @Test def compileTwo = @@ -165,4 +165,14 @@ class ReplCompilerTests extends ReplTest { run("IntOrd") assertTrue(storedOutput().startsWith("val res0: IntOrd.type =")) } + + @Test def testSingletonPrint = fromInitialState { implicit state => + run("""val a = "hello"; val x: a.type = a""") + assertEquals("val a: String = hello\nval x: a.type = hello", storedOutput().trim) + } + + @Test def i6574 = fromInitialState { implicit state => + run("val a: 1 | 0 = 1") + assertEquals("val a: 1 | 0 = 1", storedOutput().trim) + } }