aboutsummaryrefslogtreecommitdiff
path: root/compiler/tests/verifier/type_compatibility.good
blob: b37a6235d696eb7e3f9f32a97ba18d020f5a5054 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82


// Named type & named type => identity comparison
int a = ii;
T b = tt;

// Named & anonymous types => structure comparison
() c = tt;
T d = ();
() e = ();

int^ f = @a;
T^ g = @b;

()^ h = @b;
T^ i = @();
()^ j = @();
TPtr k = @d;
TPtr l = @();

RT1 m = (b,);
RT1 n = ((),);

// special handling of byte and char
byte byt = 10;
char ch = 32;
int8 i8;
uint8 u8;

// int and byte
int8^ i8bp = @byt;
uint8^ u8bp = @byt;
byte^ bp1 = @i8;
byte^ bp2 = @u8;
// int and char
int8^ i8cp = @ch;
uint8^ u8cp = @ch;
char^ cp1 = @i8;
char^ cp2 = @u8;
// non-pointer values are compatible if they have compatible ranges
byte b1 = ch;
char c1 = byt;
// casting via "as uint8^" is allowed
byte^ bp3 = @ch as uint8^;
char^ cp3 = @byt as uint8^;

// structure of array element types must match exactly
(int)#[2] arr1 = [(1,), (2,)];
V#[2] arr2 = arr1;
(int)#[2] arr3 = arr2;

// test with compatible enum types
int enum(false=0,true=1) enum1 = bb;
int enum(false=0,true=1,verytrue=2) enum2 = bb;

// Function types
FT1^ fpa = @func;
FT1^ fpb = fpa;

// types to test with
typedef T = ();
typedef U = ();
typedef TPtr = T^;  // bad code style!
typedef UPtr = U^;
typedef V = (int x);
typedef W = (int x, int y);
typedef RT1 = (T x);
typedef RT2 = (T x);

typedef FT1 = T(T x, T y);


// values to test with
int ii = 0;
T tt = ();
T tt2;
bool bb = :false;


// functions to test with
T func(T x, T y);