|
| 1 | +fun takeAnyInt(a: int) { } |
| 2 | +fun getAnyInt(): int { return 0; } |
| 3 | +fun getNullableInt32(): int32? { return 32; } |
| 4 | +fun getNullableVarInt32(): varint32? { return 32; } |
| 5 | + |
| 6 | + |
| 7 | +fun autoInferInt8(x: int8) { |
| 8 | + if (random()) { return x; } |
| 9 | + else if (random()) { return 0 as int8; } |
| 10 | + else if (random()) { return x!; } |
| 11 | + else { return x += x; } |
| 12 | +} |
| 13 | + |
| 14 | +fun autoInferUInt16Opt(x: uint16) { |
| 15 | + if (random()) { return autoInferInt8(x as int8) as uint16; } |
| 16 | + return null; |
| 17 | +} |
| 18 | + |
| 19 | +fun autoInferInt_v1() { |
| 20 | + if (random()) { return 0; } |
| 21 | + else if (random()) { return 0 as uint16; } |
| 22 | + else { return 0 as int8; } |
| 23 | +} |
| 24 | + |
| 25 | +fun autoInferInt_v2() { |
| 26 | + if (random()) { return 0 as uint1; } |
| 27 | + else if (random()) { return 0 as int123; } |
| 28 | + else { return 0 as int8; } |
| 29 | +} |
| 30 | + |
| 31 | +@method_id(101) |
| 32 | +fun test1(x: int8) { |
| 33 | + var y: int8 = x; |
| 34 | + y += x; |
| 35 | + x *= y; |
| 36 | + x = 1000000; |
| 37 | + y = x; |
| 38 | + __expect_type(x / y, "int"); |
| 39 | + __expect_type(x & y, "int"); |
| 40 | + __expect_type(x != y, "bool"); |
| 41 | + if (x != y) { return -1; } |
| 42 | + if (!(y == x)) { return -1; } |
| 43 | + |
| 44 | + var a1: uint8 = 0; |
| 45 | + var a2: uint8? = 0; |
| 46 | + var a3: uint8? = 0 as int?; |
| 47 | + __expect_type(a1, "uint8"); |
| 48 | + __expect_type(a2, "uint8"); |
| 49 | + __expect_type(a3, "uint8?"); |
| 50 | + |
| 51 | + var z = x + y; |
| 52 | + __expect_type(z, "int"); |
| 53 | + return x / y; |
| 54 | +} |
| 55 | + |
| 56 | +fun test2(): (uint8, uint8, uint8) { |
| 57 | + var x: uint1 = 1; |
| 58 | + return (1, x as uint8, x as int); |
| 59 | +} |
| 60 | + |
| 61 | +fun test3(op: int32, qid: uint64) { |
| 62 | + op = qid as int32; |
| 63 | + |
| 64 | + op + qid; |
| 65 | + op = op + qid; |
| 66 | + op = op & qid; |
| 67 | + op += qid; |
| 68 | + op &= qid; |
| 69 | + if (op == qid) {} |
| 70 | + if ((op as int32?)! == qid) {} |
| 71 | + if (op == (qid as uint64)) {} |
| 72 | + if ((op as uint257?)! != (qid as int256?)!) {} |
| 73 | + __expect_type(op << qid, "int"); |
| 74 | + |
| 75 | + takeAnyInt(op); |
| 76 | + op = getAnyInt(); |
| 77 | + |
| 78 | + __expect_type(autoInferInt8, "(int8) -> int8"); |
| 79 | + __expect_type(autoInferUInt16Opt(0), "uint16?"); |
| 80 | + __expect_type(autoInferInt_v1(), "int"); |
| 81 | + __expect_type(autoInferInt_v2(), "int"); |
| 82 | + |
| 83 | + var amount: uint100 = 1000; |
| 84 | + var percent: uint8 = 50; |
| 85 | + var new = amount * percent / 100; |
| 86 | + amount = new; |
| 87 | +} |
| 88 | + |
| 89 | +@method_id(104) |
| 90 | +fun test4(): (int32, int32?, bool, bool) { |
| 91 | + var x = getNullableInt32(); |
| 92 | + __expect_type(x, "int32?"); |
| 93 | + if (x! != x! || x! != 32) { |
| 94 | + return (0, null, false, false); |
| 95 | + } |
| 96 | + if (x == null) { |
| 97 | + return (-1, null, false, false); |
| 98 | + } |
| 99 | + x += x; |
| 100 | + return (x, x, x == x, x == getAnyInt()); |
| 101 | +} |
| 102 | + |
| 103 | +@method_id(105) |
| 104 | +fun test5() { |
| 105 | + var (x: int8, y: uint16) = (1, 2); |
| 106 | + var cell = beginCell().storeInt(x, 32).storeInt(y, 32 as int32).endCell(); |
| 107 | + var slice = cell.beginParse(); |
| 108 | + x = slice.loadInt(32); |
| 109 | + y = slice.loadInt(32); |
| 110 | + __expect_type(x & y, "int"); |
| 111 | + return (x + y, x && y, x & y); |
| 112 | +} |
| 113 | + |
| 114 | +fun test6() { |
| 115 | + var x: int11 = ~(0 as int22); |
| 116 | + while (x) {} |
| 117 | + return x ? x : 0; |
| 118 | +} |
| 119 | + |
| 120 | +fun test7() { |
| 121 | + var n = getNullableVarInt32(); |
| 122 | + __expect_type(n!, "varint32"); |
| 123 | + __expect_type(n, "varint32?"); |
| 124 | + if (n != null) { |
| 125 | + __expect_type(n, "varint32"); |
| 126 | + __expect_type(n += n, "varint32"); |
| 127 | + __expect_type(n += n as int8, "varint32"); |
| 128 | + } else { |
| 129 | + n = 0; |
| 130 | + n = 0 as varint32?; |
| 131 | + n = 0 as varint32; |
| 132 | + } |
| 133 | + __expect_type(n, "varint32"); |
| 134 | + __expect_type(n as uint32, "uint32"); |
| 135 | + __expect_type(n as varint16, "varint16"); |
| 136 | + __expect_type((n as varint16) as int, "int"); |
| 137 | +} |
| 138 | + |
| 139 | +fun test13(x1: int?, x2: int8?, x3: int, x4: int8): (int8?, int8?, int8?, int8?, int32?, int32?) { |
| 140 | + return (x1, x2, x3, x4, x4 as int32, x4 as int32?); |
| 141 | +} |
| 142 | + |
| 143 | +@method_id(114) |
| 144 | +fun test14(firstComponent: int8?): (int, int16)? { |
| 145 | + return firstComponent! < 10 ? null : (firstComponent!, 2); |
| 146 | +} |
| 147 | + |
| 148 | +fun assign0<T>(mutate v: T) { v = 0; } |
| 149 | + |
| 150 | +fun main() { |
| 151 | + var t = createEmptyTuple(); |
| 152 | + t.tuplePush(1); |
| 153 | + t.tuplePush(2); |
| 154 | + t.tuplePush(3); |
| 155 | + assign0(mutate t.0 as int8); |
| 156 | + assign0(mutate t.1 as uint16); |
| 157 | + assign0(mutate t.2 as int); |
| 158 | + __expect_type(t.0 as int1, "int1"); |
| 159 | + __expect_type(t.0 as uint257, "uint257"); |
| 160 | + __expect_type(0 as int32, "int32"); |
| 161 | + __expect_type((0 as int32) as uint64?, "uint64?"); |
| 162 | + __expect_type(null as (int8, [uint16?])?, "(int8, [uint16?])?"); |
| 163 | + __expect_type(10>3 ? 0 as uint8 : 0 as uint16, "int"); |
| 164 | + return t; |
| 165 | +} |
| 166 | + |
| 167 | +/** |
| 168 | +@testcase | 0 | | [ 0 0 0 ] |
| 169 | +@testcase | 101 | 0 | 1 |
| 170 | +@testcase | 104 | | 64 64 -1 0 |
| 171 | +@testcase | 105 | | 3 -1 0 |
| 172 | +@testcase | 114 | 5 | (null) (null) 0 |
| 173 | +@testcase | 114 | 15 | 15 2 -1 |
| 174 | + |
| 175 | +@fif_codegen DECLPROC assign0<int8> |
| 176 | +@fif_codegen DECLPROC assign0<uint16> |
| 177 | +@fif_codegen DECLPROC assign0<int> |
| 178 | +*/ |
0 commit comments