result_location_interfering_with_swap.zig (411B) - Raw
1 const expect = @import("std").testing.expect; 2 test "attempt to swap array elements with array initializer" { 3 var arr: [2]u32 = .{ 1, 2 }; 4 arr = .{ arr[1], arr[0] }; 5 // The previous line is equivalent to the following two lines: 6 // arr[0] = arr[1]; 7 // arr[1] = arr[0]; 8 // So this fails! 9 try expect(arr[0] == 2); // succeeds 10 try expect(arr[1] == 1); // fails 11 } 12 13 // test_error=