Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000304Core InformTablespublic2010-09-26 10:232010-10-28 00:30
Reporteradam 
Assigned Tograham 
PrioritynormalSeveritymildReproducibilityalways
StatusclosedResolutionfixed 
Platformx86OSMac OS XOS Version10.6
Product Version6E72 
Target VersionFixed in Version6F95 
Summary0000304: Nested loops with tables can break, causing runtime errors
DescriptionThe code below shows a runtime error and crashes after displaying the first entry from the Table of Fictional Cast members.
Minimal Source Text To Reproduce
Theater is a room.

Table of Real Cast Members
Character
"Stiffy Makane"
"Jimi Hendrix"

Table of Fictional Cast Members
Character
"The Golden Apple"
"The Philosopher's Stone"

When play begins:
    repeat through the Table of Real Cast Members
    begin;
	say "[Character entry].";
        repeat with P running from 1 to 1
        begin;
        end repeat;
    end repeat;
    repeat through the Table of Fictional Cast Members
    begin;
	say "[Character entry].";
        repeat with P running from 1 to 1
        begin;
        end repeat;
        repeat with P running from 1 to 1
        begin;
        end repeat;
    end repeat.
Additional InformationThe generated code uses the I6 local "t_0" for the "repeat through the Table of Fictional Cast Members" loop, but also reuses it for the second "repeat with P running from 1 to 1" loop inside that one, causing the loop to break after the first iteration.
TagsNo tags attached.
Effect(serious/mild) Game compiles but misbehaves
Attached Files

- Relationships
related to 0000311closedgraham Phrases with tables and too many local variables cause I6 errors 

-  Notes
(0000593)
adam (reporter)
2010-09-26 10:35

And, oddly, if you break it into a print the real cast rule and a print the fictional cast rule, it works as you would expect. Although it still fails to compile under zcode.
(0000598)
jmcgrew (administrator)
2010-09-26 13:53

It fails to compile under Z-code because, when you count the hidden variables used for tables and loops, the rule has more than 15 local variables.

I suspect the runtime error is caused by the I6 local t_1 being reused for two different purposes by an outer and inner loop:

<code>
      ! [30: repeat through the table of fictional cast members begin]
       @push ct_0; @push ct_1;
for (t_1=T3_fictional_cast_members,t_2=1,ct_0=t_1,ct_1=t_2:
t_2<=TableRows(t_1):t_2++,ct_0=t_1,ct_1=t_2)
if (TableRowIsBlank(ct_0,ct_1)==false) {
           if (debug_rules>1) print " [repetition through row ", ct_1, "]^";

...

         ! [43: repeat with q running from 1 to ns begin]
          for (t_1=1: t_1<=t_9: t_1++) {
              if (debug_rules>1) print " [repetition with Q set to ", (DecimalNumber) t_1, "]^";
</code>
(0000606)
EmacsUser (manager)
2010-09-27 19:08
edited on: 2010-09-27 19:10

A reduced test case:

Theater is a room.

Table of Real Cast Members
Character
"Stiffy Makane"

Table of Fictional Cast Members
Character
"The Golden Apple"


To debug rules:
    (- debug_rules=2; -).

When play begins:
    debug rules;
    repeat through the Table of Real Cast Members
    begin;
        repeat with P running from 1 to 1
        begin;
        end repeat;
    end repeat;
    repeat through the Table of Fictional Cast Members
    begin;
        repeat with P running from 1 to 1
        begin;
        end repeat;
        repeat with P running from 1 to 1
        begin;
        end repeat;
    end repeat.

(0000607)
jmcgrew (administrator)
2010-09-27 19:27

Updated the test case.
(0000632)
jmcgrew (administrator)
2010-09-29 12:32

Corrected the sample code and updated the summary and descriptions. I'll open a second report for the original I6 error about running out of local variables.
(0000634)
graham (administrator)
2010-09-29 14:12

A classic bug, this one. Inform was correctly allocating two variables to keep track of the table-entry loop, and setting their scope to the current block; but owing to lines of code having been accidentally transposed, it was creating a fresh block just before this, not just after, and therefore the variables expired at the end of the first inner loop, not at the end of the outer loop. This left them free for reallocation when the second inner loop arose, and so... Fixed.

- Issue History
Date Modified Username Field Change
2010-09-26 10:23 adam New Issue
2010-09-26 10:35 adam Note Added: 0000593
2010-09-26 13:53 jmcgrew Note Added: 0000598
2010-09-26 13:53 jmcgrew Status new => acknowledged
2010-09-26 13:53 jmcgrew Category Spacing and printing => Tables
2010-09-26 15:34 jmcgrew Status acknowledged => confirmed
2010-09-27 19:08 EmacsUser Note Added: 0000606
2010-09-27 19:10 EmacsUser Note Edited: 0000606 View Revisions
2010-09-27 19:27 jmcgrew Steps to Reproduce Updated View Revisions
2010-09-27 19:27 jmcgrew Note Added: 0000607
2010-09-29 12:32 jmcgrew Note Added: 0000632
2010-09-29 12:32 jmcgrew Summary Strange indexing errors when attempting to create columnar output => Nested loops with tables can break, causing runtime errors
2010-09-29 12:32 jmcgrew Description Updated View Revisions
2010-09-29 12:32 jmcgrew Steps to Reproduce Updated View Revisions
2010-09-29 12:32 jmcgrew Additional Information Updated View Revisions
2010-09-29 12:40 jmcgrew Relationship added related to 0000311
2010-09-29 14:12 graham Note Added: 0000634
2010-09-29 14:12 graham Status confirmed => resolved
2010-09-29 14:12 graham Resolution open => fixed
2010-09-29 14:12 graham Assigned To => graham
2010-10-25 21:14 jmcgrew Fixed in Version => 6F95
2010-10-28 00:30 jmcgrew Status resolved => closed


Copyright © 2000 - 2010 MantisBT Group
Powered by Mantis Bugtracker