| 1 | // Test @[heap] structs with large fixed arrays. |
| 2 | |
| 3 | @[heap] |
| 4 | struct LargeData { |
| 5 | array [1024 * 1024]int |
| 6 | } |
| 7 | |
| 8 | @[heap] |
| 9 | struct LargeDataWithFields { |
| 10 | array [1024 * 1024]int |
| 11 | value int = 42 |
| 12 | name string |
| 13 | } |
| 14 | |
| 15 | fn get_large_ref() &LargeData { |
| 16 | d := LargeData{} |
| 17 | return &d |
| 18 | } |
| 19 | |
| 20 | fn get_large_with_fields_ref(name string) &LargeDataWithFields { |
| 21 | d := LargeDataWithFields{ |
| 22 | name: name |
| 23 | } |
| 24 | return &d |
| 25 | } |
| 26 | |
| 27 | fn test_heap_large_fixed_array_basic() { |
| 28 | // Basic test: create a heap struct with large fixed array |
| 29 | d := LargeData{} |
| 30 | assert d.array[0] == 0 |
| 31 | assert d.array[1024 * 1024 - 1] == 0 |
| 32 | } |
| 33 | |
| 34 | fn test_heap_large_fixed_array_reference() { |
| 35 | // Test returning reference to heap struct with large array |
| 36 | ptr := get_large_ref() |
| 37 | assert ptr.array[0] == 0 |
| 38 | assert ptr.array[500000] == 0 |
| 39 | } |
| 40 | |
| 41 | fn test_heap_large_fixed_array_with_fields() { |
| 42 | // Test struct with large array and other fields |
| 43 | d := LargeDataWithFields{ |
| 44 | name: 'test' |
| 45 | } |
| 46 | assert d.array[0] == 0 |
| 47 | assert d.value == 42 // default value |
| 48 | assert d.name == 'test' // explicit value |
| 49 | } |
| 50 | |
| 51 | fn test_heap_large_fixed_array_with_fields_ref() { |
| 52 | // Test reference to struct with large array and fields |
| 53 | ptr := get_large_with_fields_ref('hello') |
| 54 | assert ptr.array[0] == 0 |
| 55 | assert ptr.value == 42 |
| 56 | assert ptr.name == 'hello' |
| 57 | } |
| 58 | |
| 59 | fn test_heap_large_fixed_array_multiple() { |
| 60 | // Test creating multiple large heap structs |
| 61 | a := LargeData{} |
| 62 | b := LargeData{} |
| 63 | c := LargeDataWithFields{ |
| 64 | value: 100 |
| 65 | name: 'multi' |
| 66 | } |
| 67 | assert a.array[0] == 0 |
| 68 | assert b.array[0] == 0 |
| 69 | assert c.value == 100 |
| 70 | assert c.name == 'multi' |
| 71 | } |
| 72 | |