The following statement: produces this misleading compilation error: 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. 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. is the same error.
The attached very simple patch fixes this.
It also adds a warning in cases of 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.
About Patches
Issue C63011 [previous patch]
Misleading error from 'for' statement
Submitted by: Jayzee
Appeared in: Compiler 6.30 or before
Fixed in: -
Problem
for (i : i<j : i++) { ... }
Error: Expected assignment or statement but found TARGET_ZCODE
Solution (by Cedric Knight)
[ TestRoutine i len; i; ...
i==0;
--- 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 site is no longer supported; information may be out of date.
Maintained as a historical archive by the Interactive Fiction Technology Foundation.
Copyright 1993-2018 IFTF, CC-BY-SA unless otherwise noted.
This page was originally managed by Roger Firth.