summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semstmts.nim6
-rw-r--r--doc/manual/stmts.txt10
-rw-r--r--doc/tut1.txt2
-rw-r--r--web/news.txt5
4 files changed, 15 insertions, 8 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index c386785be..063df30fd 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -199,11 +199,12 @@ proc semCase(c: PContext, n: PNode): PNode =
   var covered: BiggestInt = 0
   var typ = commonTypeBegin
   var hasElse = false
+  var notOrdinal = false
   case skipTypes(n.sons[0].typ, abstractVarRange-{tyTypeDesc}).kind
   of tyInt..tyInt64, tyChar, tyEnum, tyUInt..tyUInt32, tyBool:
     chckCovered = true
   of tyFloat..tyFloat128, tyString, tyError:
-    discard
+    notOrdinal = true
   else:
     localError(n.info, errSelectorMustBeOfCertainTypes)
     return
@@ -233,6 +234,9 @@ proc semCase(c: PContext, n: PNode): PNode =
       hasElse = true
     else:
       illFormedAst(x)
+  if notOrdinal and not hasElse:
+    message(n.info, warnDeprecated,
+            "use 'else: discard'; non-ordinal case without 'else'")
   if chckCovered:
     if covered == toCover(n.sons[0].typ):
       hasElse = true
diff --git a/doc/manual/stmts.txt b/doc/manual/stmts.txt
index b706101e1..1307ff917 100644
--- a/doc/manual/stmts.txt
+++ b/doc/manual/stmts.txt
@@ -262,13 +262,11 @@ given *slicelist* the ``else`` part is executed. If there is no ``else``
 part and not all possible values that ``expr`` can hold occur in a 
 ``slicelist``, a static error occurs. This holds only for expressions of 
 ordinal types. "All possible values" of ``expr`` are determined by ``expr``'s
-type. 
+type. To suppress the static error an ``else`` part with an
+empty ``discard`` statement should be used.
 
-If the expression is not of an ordinal type, and no ``else`` part is
-given, control passes after the ``case`` statement.
-
-To suppress the static error in the ordinal case an ``else`` part with an
-empty ``discard`` statement can be used.
+For non ordinal types it is not possible to list every possible value and so
+these always require an ``else`` part.
 
 As a special semantic extension, an expression in an ``of`` branch of a case
 statement may evaluate to a set or array constructor; the set or array is then
diff --git a/doc/tut1.txt b/doc/tut1.txt
index 2a836190c..950f758f1 100644
--- a/doc/tut1.txt
+++ b/doc/tut1.txt
@@ -312,7 +312,7 @@ the compiler that for every other value nothing should be done:
 The empty `discard statement`_ is a *do nothing* statement. The compiler knows
 that a case statement with an else part cannot fail and thus the error 
 disappears. Note that it is impossible to cover all possible string values: 
-that is why there is no such check for string cases.
+that is why string cases always need an ``else`` branch.
 
 In general the case statement is used for subrange types or enumerations where
 it is of great help that the compiler checks that you covered any possible
diff --git a/web/news.txt b/web/news.txt
index 93cb71f94..233a8e2c7 100644
--- a/web/news.txt
+++ b/web/news.txt
@@ -47,11 +47,16 @@ News
     found under the `nim-code <https://github.com/nimrod-code>`_ organisation.
   - Removed the deprecated ``web`` module, the ``httpclient`` module should
     be used instead.
+  - String case (or any non-ordinal case) statements 
+    without 'else' are deprecated.
+
 
   Language Additions
   ------------------
 
   - There is a new ``parallel`` statement for safe fork&join parallel computing.
+  - ``guard`` and ``lock`` pragmas have been implemented to support safer
+    concurrent programming.
   
 
   Library Additions