Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content.Tests/DMProject/Tests/Operators/Division.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
var/list/expected = list(
1,
"Error",
10,
"Error",
"Error",
"Error", // index 5
"Error",
Expand Down
3 changes: 3 additions & 0 deletions Content.Tests/DMProject/Tests/Operators/div_by_null.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// COMPILE ERROR OD0502
/proc/RunTest
var/test = 10/null
2 changes: 1 addition & 1 deletion Content.Tests/DMProject/Tests/Operators/valid_and_null.dm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

ASSERT(C(4) / C(2) == C(2))
ASSERT(C(null) / C(2) == C(0))
ASSERT(C(2) / C(null) == C(2))
//ASSERT(C(2) / C(null) == C(2)) // Runtime error
ASSERT(C(null) / C(null) == C(0))

ASSERT(C(4) % C(3) == C(1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

ASSERT(C(4) / C(2) == C(2))
ASSERT(C(null) / C(2) == C(0))
ASSERT(C(2) / C(null) == C(2))
ASSERT(C(null) / C(null) == C(0))
//ASSERT(C(2) / C(null) == C(2)) //compile time error
//ASSERT(C(null) / C(null) == C(0))

ASSERT(C(4) % C(3) == C(1))
ASSERT(C(null) % C(3) == C(0))
Expand Down
4 changes: 4 additions & 0 deletions DMCompiler/DM/Expressions/Binary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out

if (lhs is Number lhsNum && rhs is Number rhsNum) {
constant = new Number(Location, lhsNum.Value / rhsNum.Value);
} else if (rhs is Null) {
compiler.Emit(WarningCode.BadExpression, Location, "Division by null is invalid");
constant = null;
return false;
} else {
constant = null;
return false;
Expand Down
3 changes: 1 addition & 2 deletions OpenDreamRuntime/Procs/DMOpcodeHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,8 +1143,7 @@ public static ProcStatus Divide(DMProcState state) {
state.Push(new DreamValue(0));
break;
case DreamValue.DreamValueType.Float when second.IsNull:
state.Push(new DreamValue(first.MustGetValueAsFloat()));
break;
throw new Exception($"Attempted to divide {first} by null");
case DreamValue.DreamValueType.Float when second.Type == DreamValue.DreamValueType.Float:
var secondFloat = second.MustGetValueAsFloat();
if (secondFloat == 0) {
Expand Down
Loading