aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorJonathan Brachthäuser <jonathan@b-studios.de>2016-12-21 17:08:59 +0100
committerFelix Mulder <felix.mulder@gmail.com>2017-01-08 20:11:15 +0100
commit3c2a293c96c6f1917341086c2cbd45558b90980f (patch)
tree8d7474bffbb56f4eec8136d95acae6f5713a013f /compiler
parenta909c2fc9e95a227553ce3b0decc3aeec28b5d57 (diff)
downloaddotty-3c2a293c96c6f1917341086c2cbd45558b90980f.tar.gz
dotty-3c2a293c96c6f1917341086c2cbd45558b90980f.tar.bz2
dotty-3c2a293c96c6f1917341086c2cbd45558b90980f.zip
Add error message for dangling this in path selections
The following examples trigger the error message: val x: Foo.this = ??? // Also triggers the error: import foo.this // Additionally, also slays the compiler type X = Foo.this.type
Diffstat (limited to 'compiler')
-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}
+ |"""
+ }
}