aboutsummaryrefslogtreecommitdiff
path: root/tests/issues/test_issue_5699.odin
blob: cc91799e134637059471beb55d310d1d7b4f6748 (plain)
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
// Tests issue #5699 https://github.com/odin-lang/Odin/issues/5699
package test_issues

import "core:testing"

Issue5699_Value :: struct {
    value: i32,
}

Issue5699_Result :: union {
    Issue5699_Value,
}

test_issue_5699_increment_union :: proc(counter: ^i32) -> Issue5699_Result {
    counter^ += 1
    return Issue5699_Value{0}
}

@test
test_issue_5699_union :: proc(t: ^testing.T) {
    counter: i32 = 0
    _ = test_issue_5699_increment_union(&counter).(Issue5699_Value).value
    testing.expectf(t, counter == 1, "\n\texpected: 1\n\tgot:      %d", counter)
}

test_issue_5699_increment_any :: proc(counter: ^i32) -> any {
    counter^ += 1
    return Issue5699_Value{0}
}

@test
test_issue_5699_any :: proc(t: ^testing.T) {
    counter: i32 = 0
    _ = test_issue_5699_increment_any(&counter).(Issue5699_Value).value
    testing.expectf(t, counter == 1, "\n\texpected: 1\n\tgot:      %d", counter)
}