This instance will be upgraded to Heptapod 0.31.0 (final) on 2022-05-24 at 14:00 UTC+2 (a few minutes of down time)

Commit a01f0c1b authored by Jesse McGrew's avatar Jesse McGrew
Browse files

Don't warn about unused loop variables. [ZILF-26]

parent 3b6f61e0998b
......@@ -237,11 +237,7 @@ namespace Zilf.Compiler
if (lbr.IsEverRead || lbr.IsEverWritten)
continue;
if (lbr.Type == LocalBindingType.CompilerTemporary)
continue;
//XXX not sure about this
if (lbr.Type == LocalBindingType.RoutineRequired)
if (!lbr.Type.ShouldWarnIfUnused())
continue;
var warning = new CompilerError(
......
......@@ -20,7 +20,6 @@ using System;
using JetBrains.Annotations;
using Zilf.Emit;
using Zilf.Interpreter;
using Zilf.Interpreter.Values;
using Zilf.Language;
namespace Zilf.Compiler
......@@ -51,6 +50,19 @@ namespace Zilf.Compiler
throw new ArgumentOutOfRangeException(nameof(argType), argType, null);
}
}
public static bool ShouldWarnIfUnused(this LocalBindingType type)
{
switch (type)
{
case LocalBindingType.ProgAuxiliary:
case LocalBindingType.RoutineAuxiliary:
case LocalBindingType.RoutineOptional:
return true;
default:
return false;
}
}
}
/// <summary>
......
......@@ -227,6 +227,13 @@ namespace Zilf.Tests.Integration
.DoesNotCompile();
}
[TestMethod]
public void Unused_DO_Variables_Should_Not_Warn()
{
AssertRoutine("", "<DO (I 1 10) <TELL \"spam\">>")
.WithoutWarnings()
.Compiles();
}
#endregion
......@@ -293,6 +300,26 @@ namespace Zilf.Tests.Integration
.GivesNumber("42");
}
[TestMethod]
public void Unused_MAP_CONTENTS_Variables_Should_Not_Warn()
{
AssertRoutine("\"AUX\" CNT", "<MAP-CONTENTS (I ,STARTROOM) <SET CNT <+ .CNT 1>>>")
.WithGlobal("<ROOM STARTROOM>")
.WithGlobal("<OBJECT CHIMP (IN STARTROOM)>")
.WithGlobal("<OBJECT CHAMP (IN STARTROOM)>")
.WithGlobal("<OBJECT CHUMP (IN STARTROOM)>")
.WithoutWarnings()
.Compiles();
AssertRoutine("", "<MAP-CONTENTS (I N ,STARTROOM) <REMOVE .I>>")
.WithGlobal("<ROOM STARTROOM>")
.WithGlobal("<OBJECT CHIMP (IN STARTROOM)>")
.WithGlobal("<OBJECT CHAMP (IN STARTROOM)>")
.WithGlobal("<OBJECT CHUMP (IN STARTROOM)>")
.WithoutWarnings()
.Compiles();
}
#endregion
#region MAP-DIRECTIONS
......@@ -411,6 +438,22 @@ namespace Zilf.Tests.Integration
.GeneratesCodeNotMatching(@"PUSH");
}
[TestMethod]
public void Unused_PROG_Variables_Should_Warn()
{
AssertRoutine("", "<PROG (X) <TELL \"hi\">>")
.WithWarnings("ZIL0210")
.Compiles();
AssertRoutine("", "<BIND (X) <TELL \"hi\">>")
.WithWarnings("ZIL0210")
.Compiles();
AssertRoutine("", "<REPEAT (X) <TELL \"hi\">>")
.WithWarnings("ZIL0210")
.Compiles();
}
#endregion
#region VERSION?
......
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