Skip to content

Commit 7b89b2a

Browse files
committed
[Tolk] Stricter type aliases and equal_to for types
- Added `equal_to()` instead of comparing TypePtr pointers - Aliases referencing the same underlying type are now stricter: no silent interchangeability - Smart casts restore declared type after control flow
1 parent 08c61df commit 7b89b2a

38 files changed

+844
-439
lines changed

tolk-tester/tests/generics-2.tolk

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ type StrangeAlsoInt = StrangeInt<()>;
330330
fun test19() {
331331
var i1: StrangeInt<builder> = 20;
332332
var i2: StrangeInt<slice> = 30;
333-
var i3: StrangeInt<StrangeInt<int>> = 40 as StrangeAlsoInt;
334-
i1 = i2; i2 = i1; i1 = i3; i3 = i1;
333+
var i3: StrangeInt<StrangeInt<int>> = 40;
334+
i1 = i2 as StrangeInt<builder>; i1 = i3 as StrangeInt<builder>;
335335
return (i1 as StrangeInt<()>, i3 as StrangeAlsoInt, i1 is StrangeInt, i1 is StrangeInt<cell>, i3 is StrangeInt, i3 is StrangeAlsoInt);
336336
}
337337

@@ -376,7 +376,7 @@ fun test22(w: int | WrapperAlias<int> | slice) {
376376
WrapperAlias<MyInt> => {}
377377
slice => {}
378378
}
379-
__expect_type(w, "int | Wrapper<MyInt> | slice");
379+
__expect_type(w, "int | WrapperAlias<int> | slice");
380380
match (w) {
381381
MyInt => {}
382382
slice => {}
@@ -453,23 +453,23 @@ fun main(c: Wrapper<slice>, d: WrappedInt) {
453453
@testcase | 104 | | 11 11 13 13 13 2
454454
@testcase | 105 | 0 | 80
455455
@testcase | 105 | -1 | (null)
456-
@testcase | 106 | | (null) (null) 0 777 1 2 typeid-14
456+
@testcase | 106 | | (null) (null) 0 777 1 2 typeid-12
457457
@testcase | 107 | 5 | 20 20 5 5 20 777 (null) (null) (null) 0
458-
@testcase | 108 | 0 | 777 typeid-15 777 typeid-15
458+
@testcase | 108 | 0 | 777 typeid-1 777 typeid-1
459459
@testcase | 108 | -1 | 777 0 777 0
460460
@testcase | 109 | | 40 40 70
461461
@testcase | 110 | | 20 1 20 42
462-
@testcase | 111 | | 5 1 typeid-4 5 1 typeid-4 5 1 typeid-4 5 1 typeid-4
463-
@testcase | 112 | -1 | 10 1 777 10 1 typeid-5
464-
@testcase | 112 | 0 | 20 1 777 (null) 0 typeid-6
462+
@testcase | 111 | | 5 1 typeid-2 5 1 typeid-2 5 1 typeid-2 5 1 typeid-2
463+
@testcase | 112 | -1 | 10 1 777 10 1 typeid-3
464+
@testcase | 112 | 0 | 20 1 777 (null) 0 typeid-4
465465
@testcase | 113 | | 30 -1
466466
@testcase | 114 | | 999 (null) 2
467467
@testcase | 115 | | 10 0 200 1 -1 200 1 -1
468468
@testcase | 116 | | 1 2 3 4
469469
@testcase | 117 | | 100 123
470470
@testcase | 118 | | 123 1 777 123 1 -1 2
471471
@testcase | 119 | | 40 40 -1 -1 -1 -1
472-
@testcase | 120 | | (null) typeid-9 777 (null) (null) 0 typeid-11 -1 -1
472+
@testcase | 120 | | (null) typeid-9 777 (null) (null) 0 typeid-10 -1 -1
473473
@testcase | 123 | | 10 10 10 10 10
474474

475475

tolk-tester/tests/generics-4.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ fun main() {
176176
/**
177177
@testcase | 103 | | 10 20 30 777 40 40
178178
@testcase | 104 | | (null) (null) (null)
179-
@testcase | 105 | | -1 (null) 0 (null) typeid-6 777 0 123 0 456 typeid-5
179+
@testcase | 105 | | -1 (null) 0 (null) typeid-2 777 0 123 0 456 typeid-1
180180
@testcase | 106 | | -1 0 -1 -1
181181
@testcase | 107 | | 1 10 110 117
182182
@testcase | 108 | | 10 (null) 20

tolk-tester/tests/inline-tests.tolk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,15 +537,15 @@ fun usedIn10ButDeclaredBelow(x: int) {
537537
"""
538538
wrap16() PROC:<{
539539
IFJMP:<{
540-
139 PUSHINT
540+
129 PUSHINT
541541
OVER
542542
EQUAL
543543
IFJMP:<{
544544
DROP
545545
0 GTINT
546546
100 THROWIFNOT
547547
}>
548-
140 PUSHINT
548+
130 PUSHINT
549549
s2 POP
550550
EQUAL
551551
IFJMP:<{

tolk-tester/tests/intN-tests.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fun main() {
248248
@testcase | 110 | | 50000000 50000100 1234000000 51000000
249249
@testcase | 111 | | [ 1000000000 1000000000 1000000000 -321123456789 321123456789 1100000000 ]
250250
@testcase | 114 | 5 | (null) (null) 0
251-
@testcase | 114 | 15 | 15 2 typeid-2
251+
@testcase | 114 | 15 | 15 2 typeid-1
252252

253253
@fif_codegen DECLPROC assign0<int8>()
254254
@fif_codegen DECLPROC assign0<uint16>()

tolk-tester/tests/invalid-semantics/err-4081.tolk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fun main(w: int | WrapperAlias<int> | WrapperAlias<int8>) {
1515

1616
/**
1717
@compilation_should_fail
18-
@stderr wrong pattern matching: duplicated `Wrapper<int>`
18+
@stderr wrong pattern matching: duplicated `WrapperAlias<int>`
1919
@stderr WrapperAlias<int>
2020
*/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
struct Point {
2+
x: int
3+
y: int
4+
}
5+
6+
fun Point.getX() {
7+
return self.x
8+
}
9+
10+
/**
11+
@compilation_should_fail
12+
@stderr using `self` in a static method
13+
*/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import "@stdlib/tvm-dicts"
2+
3+
type BalanceList = dict
4+
type AssetList = dict
5+
6+
fun BalanceList.validate(self): int1 { return 0 }
7+
fun AssetList.validate(self): int2 { return 0 }
8+
9+
fun f(b: BalanceList) {
10+
if (b == null) { return }
11+
else { b = createEmptyDict() }
12+
__expect_type(b, "BalanceList");
13+
14+
if (b == null) { return }
15+
__expect_type(b, "cell");
16+
17+
b.validate()
18+
}
19+
20+
/**
21+
@compilation_should_fail
22+
@stderr call to method `validate` for type `cell` is ambiguous
23+
@stderr candidate function: `BalanceList.validate`
24+
@stderr candidate function: `AssetList.validate`
25+
*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
struct Inc { v: int32 }
2+
3+
type Msg = Inc
4+
5+
fun main(s: slice) {
6+
val msg = lazy Msg.fromSlice(s);
7+
match (msg) {
8+
else => throw 0xFFFF
9+
}
10+
}
11+
12+
/**
13+
@compilation_should_fail
14+
@stderr `match` contains only `else`, but no variants
15+
*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type BalanceDict = dict
2+
3+
fun dict.doSome(self) {}
4+
fun BalanceDict.doSome(self) {}
5+
6+
fun m(d: dict) {
7+
d.doSome()
8+
}
9+
10+
/**
11+
@compilation_should_fail
12+
@stderr call to method `doSome` for type `dict` is ambiguous
13+
@stderr candidate function: `dict.doSome`
14+
@stderr candidate function: `BalanceDict.doSome`
15+
*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type BalanceDict = dict
2+
3+
fun dict.doSome(self) {}
4+
fun BalanceDict.doSome(self) {}
5+
6+
fun m(d: BalanceDict) {
7+
d.doSome()
8+
}
9+
10+
/**
11+
@compilation_should_fail
12+
@stderr call to method `doSome` for type `BalanceDict` is ambiguous
13+
@stderr candidate function: `dict.doSome`
14+
@stderr candidate function: `BalanceDict.doSome`
15+
*/

0 commit comments

Comments
 (0)