aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/src/dotty/tools/dotc/parsing/Parsers.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala27
2 files changed, 28 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
index 18f0b42f5..5604cb9e4 100644
--- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -540,7 +540,7 @@ object Parsers {
def handleThis(qual: Ident) = {
in.nextToken()
val t = atPos(start) { This(qual) }
- if (!thisOK && in.token != DOT) syntaxError("`.' expected")
+ if (!thisOK && in.token != DOT) syntaxError(DanglingThisInPath(), start)
dotSelectors(t, finish)
}
def handleSuper(qual: Ident) = {
diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index 25db28e4a..9ba771be9 100644
--- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -966,4 +966,31 @@ object messages {
| ${"val foo: Int = 3"}
|"""
}
+
+ case class DanglingThisInPath()(implicit ctx: Context) extends Message(36) {
+ val kind = "Syntax"
+ val msg = hl"""Expected an additional member selection after the keyword ${"this"}"""
+
+ val importCode =
+ """import MyClass.this.member
+ |// ^^^^^^^
+ """
+
+ val typeCode =
+ """type T = MyClass.this.Member
+ |// ^^^^^^^
+ """
+
+ val explanation =
+ hl"""|Paths of imports and type selections must not end with the keyword ${"this"}.
+ |
+ |Maybe you forgot to select a member of ${"this"}?
+ |
+ |- Example for a valid import expression using a path
+ |${importCode}
+ |
+ |- Example for a valid type using a path
+ |${typeCode}
+ |"""
+ }
}