| 1 | (* A U8, I8 or I16 widens to INT, and a U8 or U16 to UINT, where it is |
| 2 | moved: assigned, passed, returned, as a bound or a step, and where it |
| 3 | meets an INT in an operator; a conversion's result too (report |
| 4 | 2026-10.31, sections 5.10 and 6.1). *) |
| 5 | module SmallWiden; |
| 6 | import Out; |
| 7 | |
| 8 | var g: U8; h: I16; |
| 9 | |
| 10 | proc show(n: INT); |
| 11 | begin |
| 12 | Out.int(n); Out.str(" "); |
| 13 | end; |
| 14 | |
| 15 | proc byte(i: INT): U8; |
| 16 | begin |
| 17 | return U8(i); |
| 18 | end; |
| 19 | |
| 20 | proc twice(n: INT): INT; |
| 21 | begin |
| 22 | return 2 * n; |
| 23 | end; |
| 24 | |
| 25 | proc wide(b: U8): INT; |
| 26 | begin |
| 27 | return b; (* returned *) |
| 28 | end; |
| 29 | |
| 30 | proc main*; |
| 31 | var s: []const U8; a, b: U8; c: I8; w: U16; n, i: INT; u: UINT; |
| 32 | begin |
| 33 | s := "7319"; |
| 34 | for i := 0 to LEN(s) - 1 do n := n * 10 + s[i] - '0'; end; |
| 35 | show(n); (* an element, met by an INT *) |
| 36 | a := 200; b := 100; |
| 37 | show(INT(a) + b); (* 300: the sum made in INT *) |
| 38 | show(U8(a + b)); (* 44: made in U8, then converted *) |
| 39 | c := -5; n := c; show(n); (* a signed one keeps its sign *) |
| 40 | g := 255; h := -30000; |
| 41 | show(g); show(h); (* passed *) |
| 42 | show(twice(byte(300))); (* a call's result: 88 *) |
| 43 | show(wide(a)); |
| 44 | if (a > n) and (c < n) then Out.str("compared "); end; |
| 45 | n := 0; INC(n, a); DEC(n, c); show(n); (* 205 *) |
| 46 | for i := c to c do show(i); end; (* bounds *) |
| 47 | w := 65535; u := w; show(INT(u)); |
| 48 | u := a; show(INT(u)); |
| 49 | Out.ln; |
| 50 | end; |
| 51 | |
| 52 | end SmallWiden. |