Skip to content

Commit df93037

Browse files
amylizzlewixoaGit
andauthored
Bring parity to num/null (#2432)
Co-authored-by: wixoa <[email protected]>
1 parent c496208 commit df93037

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

Content.Tests/DMProject/Tests/Operators/Division.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
var/list/expected = list(
88
1,
99
"Error",
10-
10,
10+
"Error",
1111
"Error",
1212
"Error", // index 5
1313
"Error",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// COMPILE ERROR OD0011
2+
/proc/RunTest
3+
var/test = 10/null

Content.Tests/DMProject/Tests/Operators/valid_and_null.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
ASSERT(C(4) / C(2) == C(2))
5959
ASSERT(C(null) / C(2) == C(0))
60-
ASSERT(C(2) / C(null) == C(2))
60+
//ASSERT(C(2) / C(null) == C(2)) // Runtime error
6161
ASSERT(C(null) / C(null) == C(0))
6262

6363
ASSERT(C(4) % C(3) == C(1))

Content.Tests/DMProject/Tests/Operators/valid_and_null_const.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030

3131
ASSERT(C(4) / C(2) == C(2))
3232
ASSERT(C(null) / C(2) == C(0))
33-
ASSERT(C(2) / C(null) == C(2))
34-
ASSERT(C(null) / C(null) == C(0))
33+
//ASSERT(C(2) / C(null) == C(2)) //compile time error
34+
//ASSERT(C(null) / C(null) == C(0))
3535

3636
ASSERT(C(4) % C(3) == C(1))
3737
ASSERT(C(null) % C(3) == C(0))

DMCompiler/DM/Expressions/Binary.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public override bool TryAsConstant(DMCompiler compiler, [NotNullWhen(true)] out
116116

117117
if (lhs is Number lhsNum && rhs is Number rhsNum) {
118118
constant = new Number(Location, lhsNum.Value / rhsNum.Value);
119+
} else if (rhs is Null) {
120+
compiler.Emit(WarningCode.BadExpression, Location, "Division by null is invalid");
121+
constant = null;
122+
return false;
119123
} else {
120124
constant = null;
121125
return false;

OpenDreamRuntime/Procs/DMOpcodeHandlers.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,8 +1163,7 @@ public static ProcStatus Divide(DMProcState state) {
11631163
state.Push(new DreamValue(0));
11641164
break;
11651165
case DreamValue.DreamValueType.Float when second.IsNull:
1166-
state.Push(new DreamValue(first.MustGetValueAsFloat()));
1167-
break;
1166+
throw new Exception($"Attempted to divide {first} by null");
11681167
case DreamValue.DreamValueType.Float when second.Type == DreamValue.DreamValueType.Float:
11691168
var secondFloat = second.MustGetValueAsFloat();
11701169
if (secondFloat == 0) {

0 commit comments

Comments
 (0)