Inform - Support - Patches

About Patches  

Compiler  
Library  

DM4 Errata  

Issue C63011     [previous patch]

Misleading error from 'for' statement
Submitted by: Jayzee     Appeared in: Compiler 6.30 or before     Fixed in: -
Problem

The following statement:

  for (i : i<j : i++) { ... }

produces this misleading compilation error:

  Error:  Expected assignment or statement but found TARGET_ZCODE

The error is the initialisation of 'i': 'i=0' or 'i=i' are acceptable, as is omitted the initialization altogether and, dubiously, 'i==0'. Perhaps just 'i' should have the same effect.

Solution (by Cedric Knight)

It's definitely intended to be an error, and produces the correct error message if the loop variable is a global. The same issues apply to simple statements.

  [ TestRoutine i len;  i; ... 

is the same error. The attached very simple patch fixes this. It also adds a warning in cases of

  i==0;

It strikes me that if 'i+2' is not a valid Inform statement or initialisation part of a for construct (causing an error), 'i==2' should be invalid in the same situations (causing at least a warning). It's probably easier to accidentally substitute '=' for '==' than the reverse, but it can still happen.

--- expressc.c	Sat Feb 28 06:30:00 2004
+++ expressc.c	Fri Jul 09 15:00:08 2004
@@ -431,7 +431,10 @@
                 t = (char *) (symbs[AO.value]);
             break;
         default:
-            t = (char *) (symbs[variable_tokens[AO.value]]);
+            if (AO.value < MAX_LOCAL_VARIABLES)
+                t = (char *) (local_variables.keywords[AO.value-1]);
+            else
+                t = (char *) (symbs[variable_tokens[AO.value]]);
             break;
     }
     vivc_flag = TRUE;
@@ -795,6 +798,9 @@
             if (AO.marker == SYMBOL_MV)
                 t = (char *) (symbs[AO.value]);
             break;
+        case LOCALVAR_OT:
+            t = (char *) (local_variables.keywords[AO.value-1]);
+            break;
         default:
             t = (char *) (symbs[variable_tokens[AO.value]]);
             break;
@@ -1334,6 +1340,9 @@
             make_jump_away = FALSE, make_branch_label = FALSE;
         int oc = operators[opnum].opcode_number_z-400, flag = TRUE;

+        if (void_flag)
+            warning_named("Evaluating this has no effect:",
+                operators[opnum].description);
         if (oc >= 400) { oc = oc - 400; flag = FALSE; }

         if ((oc == je_zc) && (arity == 2))
@@ -1487,6 +1496,10 @@
           to the simple "zero" test. Unfortunately, this doesn't
           work for the commutative form "(constant) 0 is equal to".
           At least I don't think it does. */
+
+      if (void_flag)
+          warning_named("Evaluating this has no effect:",
+              operators[opnum].description);

       if ((cc == &condclasses[1]) && (arity == 2)) {
         i = ET[ET[n].down].right;


Last updated 17 April 2013. This web site has not been fully supported since April 2008. Information may be out of date. This page was originally managed by Roger Firth.