diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2016-09-19 23:07:06 +0200 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2016-10-10 13:25:34 +0200 |
commit | bf8803d6d5b49e20e043564129c2109892842fa7 (patch) | |
tree | 3950bec472a60d5f0eadf986c4201d366b4a4d96 /src/dotty/tools/dotc/reporting/diagnostic/messages.scala | |
parent | 146add1421f4a92396fc2461ff362fee4527d7f8 (diff) | |
download | dotty-bf8803d6d5b49e20e043564129c2109892842fa7.tar.gz dotty-bf8803d6d5b49e20e043564129c2109892842fa7.tar.bz2 dotty-bf8803d6d5b49e20e043564129c2109892842fa7.zip |
Add deprecation message on `with` type operator
Diffstat (limited to 'src/dotty/tools/dotc/reporting/diagnostic/messages.scala')
-rw-r--r-- | src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 124 |
1 files changed, 77 insertions, 47 deletions
diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 4b7502287..cf67e8989 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -13,7 +13,7 @@ import dotc.printing.SyntaxHighlighting._ object messages { - /** Concrete messages to be consumed by the reporter ---------------------- */ + /** Message container to be consumed by the reporter ---------------------- */ class Error( msgFn: => Message, pos: SourcePosition, @@ -98,54 +98,84 @@ object messages { /** Syntax Errors --------------------------------------------------------- */ abstract class EmptyCatchOrFinallyBlock(tryBody: untpd.Tree, errNo: String)(implicit ctx: Context) extends Message(errNo) { - val explanation = { - val tryString = tryBody match { - case Block(Nil, untpd.EmptyTree) => "{}" - case _ => tryBody.show - } - - val code1 = - s"""|try $tryString catch { - | case t: Throwable => ??? - |}""".stripMargin - - val code2 = - s"""|try $tryString finally { - | // perform your cleanup here! - |}""".stripMargin - - hl"""|A ${"try"} expression should be followed by some mechanism to handle any exceptions - |thrown. Typically a ${"catch"} expression follows the ${"try"} and pattern matches - |on any expected exceptions. For example: - | - |$code1 - | - |It is also possible to follow a ${"try"} immediately by a ${"finally"} - letting the - |exception propagate - but still allowing for some clean up in ${"finally"}: - | - |$code2""".stripMargin - } - } - - class EmptyCatchBlock(tryBody: untpd.Tree)(implicit ctx: Context) - extends EmptyCatchOrFinallyBlock(tryBody, "E001") { - val kind = "Syntax" - val msg = - hl"""|The ${"catch"} block does not contain a valid expression, try - |adding a case like - `${"case e: Exception =>"}` to the block""".stripMargin - } - - case class EmptyCatchAndFinallyBlock(tryBody: untpd.Tree)(implicit ctx: Context) - extends EmptyCatchOrFinallyBlock(tryBody, "E002") { - val kind = "Syntax" - val msg = - hl"""|A ${"try"} without ${"catch"} or ${"finally"} is equivalent to putting - |its body in a block; no exceptions are handled.""".stripMargin - } + val explanation = { + val tryString = tryBody match { + case Block(Nil, untpd.EmptyTree) => "{}" + case _ => tryBody.show + } + + val code1 = + s"""|try $tryString catch { + | case t: Throwable => ??? + |}""".stripMargin + + val code2 = + s"""|try $tryString finally { + | // perform your cleanup here! + |}""".stripMargin + + hl"""|A ${"try"} expression should be followed by some mechanism to handle any exceptions + |thrown. Typically a ${"catch"} expression follows the ${"try"} and pattern matches + |on any expected exceptions. For example: + | + |$code1 + | + |It is also possible to follow a ${"try"} immediately by a ${"finally"} - letting the + |exception propagate - but still allowing for some clean up in ${"finally"}: + | + |$code2""".stripMargin + } + } + + class EmptyCatchBlock(tryBody: untpd.Tree)(implicit ctx: Context) + extends EmptyCatchOrFinallyBlock(tryBody, "E001") { + val kind = "Syntax" + val msg = + hl"""|The ${"catch"} block does not contain a valid expression, try + |adding a case like - `${"case e: Exception =>"}` to the block""".stripMargin + } + + case class EmptyCatchAndFinallyBlock(tryBody: untpd.Tree)(implicit ctx: Context) + extends EmptyCatchOrFinallyBlock(tryBody, "E002") { + val kind = "Syntax" + val msg = + hl"""|A ${"try"} without ${"catch"} or ${"finally"} is equivalent to putting + |its body in a block; no exceptions are handled.""".stripMargin + } + + case class DeprecatedWithOperator()(implicit ctx: Context) + extends Message("E003") { + val kind = "Syntax" + val msg = + hl"""${"with"} as a type operator has been deprecated; use `&' instead""" + val explanation = { + val codeBlock1 = + """|trait A { + | type T = Int + |} + | + |trait B { + | type T = Double + |}""".stripMargin + + hl"""|Dotty introduces intersection types - `&' types. These replace the + |use of the ${"with"} keyword. There are a few differences in + |semantics between intersection types and using `${"with"}'. + | + |`${"A with B"}' is ordered, `${"A & B"}' is not. + | + |In: + | + |$codeBlock1 + | + |The type of `${"T"}' in `${"A with B"}' is ${"Int"} whereas in `${"A & B"}' + |the type of `${"T"}' is ${"Int & Double"}.""".stripMargin + } + } /** Type Errors ----------------------------------------------------------- */ class DuplicateBind(bind: untpd.Bind, tree: untpd.CaseDef)(implicit ctx: Context) - extends Message("E003") { + extends Message("E004") { val kind = "Naming" val msg = em"duplicate pattern variable: `${bind.name}`" @@ -172,7 +202,7 @@ object messages { } class MissingIdent(tree: untpd.Ident, treeKind: String, name: Name)(implicit ctx: Context) - extends Message("E004") { + extends Message("E005") { val kind = "Missing identifier" val msg = em"not found: $treeKind$name" |