Update to commit e2647ad952b4d7afc9a186429c181efbc4958786
[inform.git] / src / arrays.c
index fc4f7af2c5e6abb7f1f951920138bf7dbdfd991a..c1f410ce34b9d47f1513c957c6ac5af927aaf18d 100644 (file)
@@ -3,9 +3,8 @@
 /*               likewise global variables, which are in some ways a         */
 /*               simpler form of the same thing.                             */
 /*                                                                           */
-/* Copyright (c) Graham Nelson 1993 - 2020                                   */
-/*                                                                           */
-/* This file is part of Inform.                                              */
+/*   Part of Inform 6.35                                                     */
+/*   copyright (c) Graham Nelson 1993 - 2020                                 */
 /*                                                                           */
 /* Inform is free software: you can redistribute it and/or modify            */
 /* it under the terms of the GNU General Public License as published by      */
@@ -95,6 +94,10 @@ extern void finish_array(int32 i, int is_static)
       area = static_array_area;
       area_size = static_array_area_size;
   }
+
+  if (i == 0) {
+      error("An array must have at least one entry");
+  }
   
     /*  Write the array size into the 0th byte/word of the array, if it's
         a "table" or "string" array                                          */
@@ -259,7 +262,7 @@ extern void array_entry(int32 i, int is_static, assembly_operand VAL)
 /*                                                                           */
 /*      | ->       |  <number-of-entries>                                    */
 /*      | -->      |  <entry-1> ... <entry-n>                                */
-/*      | string   |  [ <entry-1> [,] [;] <entry-2> ... <entry-n> ];         */
+/*      | string   |  [ <entry-1> [;] <entry-2> ... <entry-n> ];             */
 /*      | table                                                              */
 /*      | buffer                                                             */
 /*                                                                           */
@@ -311,7 +314,7 @@ extern void make_global(int array_flag, int name_only)
             goto RedefinitionOfSystemVar;
     }
 
-    if ((token_type != SYMBOL_TT) || (!(sflags[i] & UNKNOWN_SFLAG)))
+    if (token_type != SYMBOL_TT)
     {   discard_token_location(beginning_debug_location);
         if (array_flag)
             ebf_error("new array name", token_text);
@@ -319,6 +322,14 @@ extern void make_global(int array_flag, int name_only)
         panic_mode_error_recovery(); return;
     }
 
+    if (!(sflags[i] & UNKNOWN_SFLAG))
+    {   discard_token_location(beginning_debug_location);
+        if (array_flag)
+            ebf_symbol_error("new array name", token_text, typename(stypes[i]), slines[i]);
+        else ebf_symbol_error("new global variable name", token_text, typename(stypes[i]), slines[i]);
+        panic_mode_error_recovery(); return;
+    }
+
     if ((!array_flag) && (sflags[i] & USED_SFLAG))
         error_named("Variable must be defined before use:", token_text);
 
@@ -544,8 +555,8 @@ extern void make_global(int array_flag, int name_only)
 
             CalculatedArraySize:
 
-            if (module_switch && (AO.marker != 0))
-            {   error("Array sizes must be known now, not externally defined");
+            if (AO.marker != 0)
+            {   error("Array sizes must be known now, not defined later");
                 break;
             }