Skip to content

Commit 2fd613f

Browse files
authored
Adds an exception to 'turn()' on invalid direction types (#2371)
1 parent d44fb64 commit 2fd613f

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

Content.Tests/DMProject/Tests/Builtins/turn.dm

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,3 @@
5151
ASSERT(turn(WEST, -22) == WEST)
5252
ASSERT(turn(WEST, -44) == WEST)
5353
ASSERT(turn(WEST, -75) == NORTHWEST)
54-
55-
// An invalid first arg but valid second arg should give a random direction
56-
// It's a little hard to test for randomness here, so just verify it's within the range of valid directions
57-
var/shouldBeRandomDir = turn(0, 90)
58-
ASSERT(shouldBeRandomDir >= 1 && shouldBeRandomDir <= 10)
59-
shouldBeRandomDir = turn("NORTH", 90)
60-
ASSERT(shouldBeRandomDir >= 1 && shouldBeRandomDir <= 10)

OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3107,7 +3107,10 @@ public static DreamValue NativeProc_turn(NativeProc.Bundle bundle, DreamObject?
31073107
return DreamProcNativeMatrix._NativeProc_TurnInternal(bundle.ObjectTree, clonedMatrix, angle);
31083108
}
31093109

3110-
dirArg.TryGetValueAsInteger(out int possibleDir);
3110+
// If Dir is not an integer, throw
3111+
if (!dirArg.TryGetValueAsInteger(out int possibleDir)) {
3112+
throw new Exception("expected icon, matrix or integer");
3113+
}
31113114

31123115
AtomDirection dir = (AtomDirection)possibleDir;
31133116
float? dirAngle = dir switch {

0 commit comments

Comments
 (0)