linkname ""; import int memset(var any ^obj, int value, count len); var int state = 0; byte runonce(byte expected) { if state != 0 return 99; state = 1; return expected; } () without_temporaries() { // These should not require temporaries var int mixed; int i = 123; byte b = 1; mixed = i + b; assert mixed == 124; } int main() { int#[2,3] arr1 = [[11,12,13], [24,25,26]]; var int#[2,3] arr2; without_temporaries(); { // just a check that temporaries are allocated // correctly in nested statements arr2 = arr1; } arr2 = arr1; assert arr2#[0,0] == 11; assert arr2#[1,2] == 26; assert arr1 == arr2; // tests both equality and the comparison operator assert not (arr1 != arr2); { state = 0; byte#[3]? a = makeopt [1,runonce(2),3]; state = 0; byte#[3]? b = makeopt [1,runonce(2),3]; assert a?#[0] == 1; assert a?#[1] == 2; assert a?#[2] == 3; assert a != none; assert not a == none; assert a == b; assert not a != b; assert a? == b?; assert not a? != b?; } { var (byte x, int y, (int zz) z, int#[3] arr) value; typedef Struct1 = (byte x, int, (int zz) z, int#[3]); var (byte, int y, (int zz), int#[3]) a; var (byte, int y, (int zz), int#[3]) b; var Struct1 c; // Use memset to make two different struct values with // different data in the padding memset(@value, 0xFF, sizeof value); value.x = 123; value.y = 456; value.z = (678,); value.arr = [1111,2222,3333]; a = value; memset(@value, 0x00, sizeof value); value.x = 123; value.y = 456; value.z = (678,); value.arr = [1111,2222,3333]; b = value; // Comparison with exactly the same type assert a == a; assert not a != a; assert a == b; assert b == a; assert not a != b; assert not b != a; // Comparison with a compatible type c = value; assert a == c; assert c == a; assert not a != c; assert not c != a; } // TODO test zero-length arrays and empty structs also? return 0; }