From 9ffa984dda83413ad719b76ea63d86ec363695fb Mon Sep 17 00:00:00 2001 From: Hermes Date: Mon, 29 Oct 2018 17:58:23 -0600 Subject: [PATCH 1/4] stable identifier message --- .../tools/dotc/reporting/diagnostic/ErrorMessageID.java | 3 ++- .../dotty/tools/dotc/reporting/diagnostic/messages.scala | 8 ++++++++ compiler/src/dotty/tools/dotc/typer/Typer.scala | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index 1877f68df87d..af682ef9398b 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -141,7 +141,8 @@ public enum ErrorMessageID { LazyStaticFieldID, StaticOverridingNonStaticMembersID, OverloadInRefinementID, - NoMatchingOverloadID + NoMatchingOverloadID, + StableIdentPatternID ; public int errorNumber() { diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 2b852e5cf6ca..26a4559e6fd8 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -2191,4 +2191,12 @@ object messages { val kind: String = "Type Mismatch" val explanation: String = "" } + case class StableIdentPattern(tree: untpd.Tree, pt: Type)(implicit val ctx: Context) + extends Message(StableIdentPatternID) { + override def kind: String = "Syntax" + override def msg: String = { + hl"""|Stable identifier required, but ${tree.show} found""" + } + override def explanation: String = "" + } } diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 59b151e604e2..351adfb98839 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -414,7 +414,7 @@ class Typer extends Namer !pt.isInstanceOf[ApplyingProto] && !tree.tpe.isStable && !isWildcardArg(tree)) - ctx.error(s"stable identifier required, but ${tree.show} found", tree.pos) + ctx.error(StableIdentPattern(tree, pt), tree.pos) tree } From b456c1b4ab547faf795aa42f6f051b16c801a47e Mon Sep 17 00:00:00 2001 From: Hermes Date: Mon, 29 Oct 2018 19:29:59 -0600 Subject: [PATCH 2/4] stable identifiers test --- .../dotc/reporting/ErrorMessagesTests.scala | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index 4710e410c71e..8fa43fce7a96 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -1605,4 +1605,23 @@ class ErrorMessagesTests extends ErrorMessagesTest { message.msg ) } + + @Test def StableIdentifiers() = + checkMessagesAfter(FrontEnd.name) { + """ + | object Test { + | var x = 2 + | def test = 2 match { + | case `x` => x + 1 + | } + | } + """.stripMargin + }.expect { (_, messages) => + assertMessageCount(1, messages) + val message = message.head + assertTrue(message.isInstanceOf[StableIdentPattern]) + assertEquals( + "Stable identifier required, but `x` found" + ) + } } From 0984da34d6496ce1fceb9d517c38b1a36898e4b7 Mon Sep 17 00:00:00 2001 From: Hermes Date: Thu, 13 Dec 2018 11:18:26 -0600 Subject: [PATCH 3/4] assert message text --- .../test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index 8fa43fce7a96..422110d7b141 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -1621,7 +1621,8 @@ class ErrorMessagesTests extends ErrorMessagesTest { val message = message.head assertTrue(message.isInstanceOf[StableIdentPattern]) assertEquals( - "Stable identifier required, but `x` found" + "Stable identifier required, but `x` found", + message.msg ) } } From 308e33f747dfff7c0e5dbfa860587255b4899f00 Mon Sep 17 00:00:00 2001 From: Hermes Date: Thu, 13 Dec 2018 11:55:09 -0600 Subject: [PATCH 4/4] rewrite error message --- .../src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 5 ++--- .../test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 26a4559e6fd8..9211bbcd33bd 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -2194,9 +2194,8 @@ object messages { case class StableIdentPattern(tree: untpd.Tree, pt: Type)(implicit val ctx: Context) extends Message(StableIdentPatternID) { override def kind: String = "Syntax" - override def msg: String = { - hl"""|Stable identifier required, but ${tree.show} found""" - } + override def msg: String = + hl"""Stable identifier required, but ${tree.show} found""" override def explanation: String = "" } } diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index 422110d7b141..037430b7cdd0 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -1618,7 +1618,7 @@ class ErrorMessagesTests extends ErrorMessagesTest { """.stripMargin }.expect { (_, messages) => assertMessageCount(1, messages) - val message = message.head + val message = messages.head assertTrue(message.isInstanceOf[StableIdentPattern]) assertEquals( "Stable identifier required, but `x` found",