-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogical_operators_test.gml
More file actions
44 lines (33 loc) · 1.56 KB
/
logical_operators_test.gml
File metadata and controls
44 lines (33 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Test for logical operators: type safety and short-circuit evaluation
// This test demonstrates that the compiler now correctly:
// 1. Handles i1 types without incorrect double casting
// 2. Implements short-circuit evaluation for && and ||
function demonstrate_fixes() {
var x = 5;
var y = 3;
// Basic boolean comparisons - these create i1 types
var isEqual = (x == y); // false (i1 type)
var isNotEqual = (x != y); // true (i1 type)
var isGreater = (x > y); // true (i1 type)
// Before fix: these would incorrectly load i1 as double
// After fix: these correctly use i1 types throughout
var and_result = isEqual && isNotEqual; // false && true = false
var or_result = isEqual || isNotEqual; // false || true = true
// Complex chained logical operations
var complex = (x > y) && (y > 0) && (x < 10); // true && true && true = true
// Short-circuit demonstration with side effects
var counter = 0;
// This should NOT increment counter (short-circuit)
var test1 = false && ((counter = counter + 1) > 0);
// This SHOULD increment counter
var test2 = true && ((counter = counter + 10) > 0);
// This should NOT increment counter by 100 (short-circuit)
var test3 = true || ((counter = counter + 100) > 0);
// This SHOULD increment counter by 1000
var test4 = false || ((counter = counter + 1000) > 0);
return counter; // Should return 1010 (0 + 10 + 1000)
}
// Global test variables
var a = 7;
var b = 3;
var result = demonstrate_fixes();