This instance will be upgraded to Heptapod 0.17.2 on 2020-12-03 at 14:00 UTC+1 (a few minutes of down time)

Commit e9bf8f16 authored by Jesse McGrew's avatar Jesse McGrew

Issue warning MDL0428 for LEXV tables initialized with the wrong number of elements.

parent bbabbd713ccf
......@@ -265,6 +265,8 @@ namespace Zilf.Diagnostics
public const int Too_Many_0_Only_1_Allowed_In_This_Vocab_Format = 426;
[Error("{0}: routines may not define \"BIND\", \"TUPLE\", or \"ARGS\" arguments")]
public const int _0_Routines_May_Not_Define_BIND_TUPLE_Or_ARGS_Arguments = 427;
[Warning("{0}: LEXV table initializer is not a multiple of 3 elements")]
public const int _0_LEXV_Table_Initializer_Is_Not_A_Multiple_Of_3_Elements = 428;
// Modularity (package system, definitions sections) - 0500
......
......@@ -524,6 +524,17 @@ namespace Zilf.Interpreter
}
}
if ((flags & TableFlags.Lexv) != 0)
{
var elementCount = count * Math.Max(initializer.Length, 1);
if ((elementCount % 3) != 0)
{
ctx.HandleError(new InterpreterError(
InterpreterMessages._0_LEXV_Table_Initializer_Is_Not_A_Multiple_Of_3_Elements,
"ITABLE"));
}
}
var tab = ZilTable.Create(count, initializer.Length == 0 ? null : initializer, flags, null);
tab.SourceLine = ctx.TopFrame.SourceLine;
if ((flags & TableFlags.TempTable) == 0)
......
......@@ -60,6 +60,25 @@ namespace Zilf.Tests.Integration
"<==? <GET ,TBL1 5> 3>");
}
[TestMethod]
public void ITABLE_LEXV_Should_Warn_If_Not_A_Multiple_Of_3_Elements()
{
AssertGlobals(
"<CONSTANT LEXBUF <ITABLE 1 (LEXV) 0 0>>")
.WithWarnings("MDL0428")
.Compiles();
AssertGlobals(
"<CONSTANT LEXBUF <ITABLE 1 (LEXV)>>")
.WithWarnings("MDL0428")
.Compiles();
AssertGlobals(
"<CONSTANT LEXBUF <ITABLE 3 (LEXV)>>")
.WithoutWarnings()
.Compiles();
}
[TestMethod]
public void TABLE_PATTERN_Should_Affect_Element_Sizes()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment