diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero1.dm b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero1.dm index bf3227ba91..6fed176183 100644 --- a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero1.dm +++ b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero1.dm @@ -1,4 +1,4 @@ -// COMPILE ERROR +// COMPILE ERROR OD0011 var/a = 1 / 0 diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero3.dm b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero3.dm index c3b8f68e03..95f4fef712 100644 --- a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero3.dm +++ b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero3.dm @@ -1,4 +1,4 @@ -// COMPILE ERROR +// COMPILE ERROR OD0011 var/static/a = 1 / 0 diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero6.dm b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero6.dm index 7cb5c6ccc5..b637530b11 100644 --- a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero6.dm +++ b/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero6.dm @@ -1,4 +1,4 @@ -// COMPILE ERROR +// COMPILE ERROR OD0011 var/const/a = 0 var/b = 1 / a diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero2.dm b/Content.Tests/DMProject/Tests/Tree/Const/Div_Zero/div_zero2.dm similarity index 100% rename from Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero2.dm rename to Content.Tests/DMProject/Tests/Tree/Const/Div_Zero/div_zero2.dm diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero4.dm b/Content.Tests/DMProject/Tests/Tree/Const/Div_Zero/div_zero4.dm similarity index 76% rename from Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero4.dm rename to Content.Tests/DMProject/Tests/Tree/Const/Div_Zero/div_zero4.dm index 227b380ca5..73064bbe1d 100644 --- a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero4.dm +++ b/Content.Tests/DMProject/Tests/Tree/Const/Div_Zero/div_zero4.dm @@ -1,4 +1,4 @@ -// COMPILE ERROR +// COMPILE ERROR OD0011 /proc/one() return 1 diff --git a/Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero5.dm b/Content.Tests/DMProject/Tests/Tree/Const/Div_Zero/div_zero5.dm similarity index 100% rename from Content.Tests/DMProject/Broken Tests/Tree/Const/Div_Zero/div_zero5.dm rename to Content.Tests/DMProject/Tests/Tree/Const/Div_Zero/div_zero5.dm diff --git a/Content.Tests/DMTests.cs b/Content.Tests/DMTests.cs index 684534e7e2..7cff12fd0a 100644 --- a/Content.Tests/DMTests.cs +++ b/Content.Tests/DMTests.cs @@ -79,6 +79,7 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags, int errorCode) { Assert.That(compiledFile is not null && File.Exists(compiledFile), "Failed to compile DM source file"); Assert.That(_dreamMan.LoadJson(compiledFile), $"Failed to load {compiledFile}"); + _dreamMan.LastDMException = null; // Nuke any exception from a prior test _dreamMan.StartWorld(); (bool successfulRun, DreamValue? returned, Exception? exception) = RunTest(); @@ -114,8 +115,6 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags, int errorCode) { } private (bool Success, DreamValue? Returned, Exception? except) RunTest() { - var prev = _dreamMan.LastDMException; - DreamValue? retValue = null; Task callTask = null!; @@ -143,7 +142,7 @@ public void TestFiles(string sourceFile, DMTestFlags testFlags, int errorCode) { } } - bool retSuccess = _dreamMan.LastDMException == prev; // Works because "null == null" is true in this language. + bool retSuccess = _dreamMan.LastDMException == null; // Works because "null == null" is true in this language. return (retSuccess, retValue, _dreamMan.LastDMException); } diff --git a/DMCompiler/Optimizer/PeepholeOptimizations.cs b/DMCompiler/Optimizer/PeepholeOptimizations.cs index 6b2b9ed3e1..47cb587c27 100644 --- a/DMCompiler/Optimizer/PeepholeOptimizations.cs +++ b/DMCompiler/Optimizer/PeepholeOptimizations.cs @@ -1,4 +1,5 @@ using DMCompiler.Bytecode; +using DMCompiler.Compiler; // ReSharper disable UnusedType.Global @@ -458,6 +459,10 @@ public void Apply(DMCompiler compiler, List input, int index IOptimization.GetInstructionAndValue(input[index + 1], out var pushVal2); + if (pushVal2 == 0) { + compiler.Emit(WarningCode.BadExpression, input[index + 1].GetLocation(), "Division by zero"); + } + // At runtime, given "A / B" we pop B then A // In the peephole optimizer, index is "A", index+1 is "B" var args = new List(1) {new AnnotatedBytecodeFloat(pushVal1 / pushVal2, firstInstruction.Location)};