diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index f3153592a73c..ab81c2383b26 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -141,6 +141,10 @@ class PlainPrinter(_ctx: Context) extends Printer { ParamRefNameString(tp) ~ ".type" case tp: TypeParamRef => ParamRefNameString(tp) ~ lambdaHash(tp.binder) + case tp: ConstantType => + toTextRef(tp) + case tp: TermRef => + toTextPrefix(tp.prefix) ~ selectionString(tp) ~ ".type" case tp: SingletonType => toTextLocal(tp.underlying) ~ "(" ~ toTextRef(tp) ~ ")" case AppliedType(tycon, args) => diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index ef685b0dc0f2..25b32ced4fed 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1371,27 +1371,25 @@ object messages { |""" } - case class MethodDoesNotTakeParameters(tree: tpd.Tree, methPartType: Types.Type)(err: typer.ErrorReporting.Errors)(implicit ctx: Context) + case class MethodDoesNotTakeParameters(tree: tpd.Tree, methodStr: String)(implicit ctx: Context) extends Message(MethodDoesNotTakeParametersId) { private val more = tree match { case Apply(_, _) => " more" case _ => "" } - val msg = hl"${err.refStr(methPartType)} does not take$more parameters" + val msg = hl"$methodStr does not take$more parameters" val kind = "Reference" - private val noParameters = if (methPartType.widenSingleton.isInstanceOf[ExprType]) - hl"""|As ${err.refStr(methPartType)} is defined without parenthesis, you may - |not use any at call-site, either. - |""" - else - "" + val explanation = { + val isNullary = tpd.methPart(tree).tpe.widenSingleton.isInstanceOf[ExprType] + val addendum = + if (isNullary) "\nNullary methods may not be called with parenthesis" + else "" - val explanation = - s"""|You have specified more parameter lists as defined in the method definition(s). - |$noParameters""".stripMargin + "You have specified more parameter lists as defined in the method definition(s)." + addendum + } } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index f9c7fdaeef7b..baa65cf08dfd 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2138,7 +2138,7 @@ class Typer extends Namer else tree case _ => tryInsertApplyOrImplicit(tree, pt, locked) { - errorTree(tree, MethodDoesNotTakeParameters(tree, methPart(tree).tpe)(err)) + errorTree(tree, MethodDoesNotTakeParameters(tree, methodStr)) } } diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index 101d5664973c..6f7405c225f4 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -347,10 +347,10 @@ class ErrorMessagesTests extends ErrorMessagesTest { implicit val ctx: Context = ictx assertMessageCount(1, messages) - val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages + val MethodDoesNotTakeParameters(tree, methodStr) :: Nil = messages assertEquals("Scope.foo", tree.show) - assertEquals("=> Unit(Scope.foo)", methodPart.show) + assertEquals("method foo in object Scope", methodStr) } @Test def methodDoesNotTakeMorePrameters = @@ -365,11 +365,10 @@ class ErrorMessagesTests extends ErrorMessagesTest { .expect { (ictx, messages) => implicit val ctx: Context = ictx - assertMessageCount(1, messages) - val MethodDoesNotTakeParameters(tree, methodPart) :: Nil = messages + val MethodDoesNotTakeParameters(tree, methodStr) :: Nil = messages assertEquals("Scope.foo(1)", tree.show) - assertEquals("((a: Int): Unit)(Scope.foo)", methodPart.show) + assertEquals("method foo in object Scope", methodStr) } @Test def ambiugousOverloadWithWildcard = diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 855e781ff61a..5cc54edc0270 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -125,4 +125,9 @@ class ReplCompilerTests extends ReplTest { compile("def f(g: => Int): Int = g") assertTrue(storedOutput().startsWith("def f(g: => Int): Int")) } + + @Test def singletonType: Unit = fromInitialState { implicit state => + compile("""val a = "foo"; val x: a.type = a""") + assertTrue(storedOutput().contains("""val x: a.type = "foo"""")) + } }