aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
diff options
context:
space:
mode:
authorSebastian Harko <sebastian.harko@lightbend.com>2016-10-16 02:19:33 -0700
committerSebastian Harko <sebastian.harko@lightbend.com>2016-10-16 02:19:33 -0700
commitc44a63e2574e2eca2b8f089920071f1d80aa7add (patch)
treee59c8c6edc5aa303e239ad3a3f5809092bc86cf1 /src/dotty/tools/dotc/reporting/diagnostic/messages.scala
parent5ebd55243ccc5ca637aa8c32f085a3ffb0fd93cb (diff)
downloaddotty-c44a63e2574e2eca2b8f089920071f1d80aa7add.tar.gz
dotty-c44a63e2574e2eca2b8f089920071f1d80aa7add.tar.bz2
dotty-c44a63e2574e2eca2b8f089920071f1d80aa7add.zip
explanation for error message related to use of early definitions
Diffstat (limited to 'src/dotty/tools/dotc/reporting/diagnostic/messages.scala')
-rw-r--r--src/dotty/tools/dotc/reporting/diagnostic/messages.scala44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
index 9cfac4801..9a02e0b04 100644
--- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
+++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
@@ -274,4 +274,48 @@ object messages {
val explanation = ""
}
+
+ case class EarlyDefinitionsNotSupported()(implicit ctx:Context) extends Message(9) {
+ val kind = "Syntax"
+
+ val msg = "early definitions are not supported; use trait parameters instead"
+
+ val code1 =
+ """|trait Logging {
+ | val f: File
+ | f.open()
+ | onExit(f.close())
+ | def log(msg: String) = f.write(msg)
+ |}
+ |
+ |class B extends Logging {
+ | val f = new File("log.data") // triggers a null pointer exception
+ |}
+ |
+ |class C extends {
+ | val f = new File("log.data") // early definition gets around the null pointer exception
+ |} with Logging""".stripMargin
+
+ val code2 =
+ """|trait Logging(f: File) {
+ | f.open()
+ | onExit(f.close())
+ | def log(msg: String) = f.write(msg)
+ |}
+ |
+ |class C extends Logging(new File("log.data"))""".stripMargin
+
+ val explanation =
+ hl"""Earlier versions of Scala did not support trait parameters and "early definitions" (also known as "early initializers")
+ |were used as an alternative.
+ |
+ |Example of old syntax:
+ |
+ |$code1
+ |
+ |The above code can now be written as:
+ |
+ |$code2
+ |""".stripMargin
+ }
}