Skip to content

Commit 3f4eca4

Browse files
committed
[Tolk] Better resolve receivers for conflicting names
Allow `fun address.staticMethod`. Before, it was not allowed due to a global `address` function. Now, the type has more precedence.
1 parent 52bcce6 commit 3f4eca4

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

tolk-tester/tests/calls-tests.tolk

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ fun test8() {
150150
return (createTFrom(), createTFrom((5, (8, createTFrom().0))));
151151
}
152152

153+
fun int(initial: int) { return initial }
154+
fun int.create0() { return 0 }
155+
fun int.plus1(self) { return self + 1 }
156+
157+
@method_id(109)
158+
fun test9() {
159+
return int(10) + int(5).plus1() + int.create0() + int.create0().plus1();
160+
}
161+
153162
fun main() {}
154163

155164
/**
@@ -161,4 +170,5 @@ fun main() {}
161170
@testcase | 106 | 0 | 5 -5 50 -50 0
162171
@testcase | 107 | | 16 5
163172
@testcase | 108 | | [ 1 2 3 ] [ 5 8 1 ]
173+
@testcase | 109 | | 17
164174
*/

tolk-tester/tests/parse-address.tolk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ fun verifyAddr(addr: address, workchain: int, number: int) {
2121
assert (s.loadUint(256) == number) throw 111;
2222
}
2323

24+
fun address.createNone() {
25+
return createAddressNone()
26+
}
27+
2428
fun check0(addr: address) {
2529
assert (addr.getWorkchain() == 0) throw 111;
2630
}
@@ -134,7 +138,7 @@ fun main() {
134138
cc2 != cc1,
135139
(cc1 as slice).bitsEqual(((cc2 as slice) as address) as slice),
136140
createAddressNone() == cc1,
137-
createAddressNone() == createAddressNone(),
141+
createAddressNone() == address.createNone(),
138142
check0(address("0:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFfffffffffffffffffffffffffffff"))
139143
);
140144
}

tolk/pipe-resolve-types.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ class ResolveTypesInsideFunctionVisitor final : public ASTVisitorFunctionBody {
467467
// for static method calls, like "int.zero()" or "Point.create()", dot obj symbol is unresolved for now
468468
// so, resolve it as a type and store as a "type reference symbol"
469469
if (auto obj_ref = v->get_obj()->try_as<ast_reference>()) {
470-
if (obj_ref->sym == nullptr) {
470+
// also, `someFn.prop` doesn't make any sense, show "unknown type"; it also forces `address.staticMethod()` to work
471+
if (obj_ref->sym == nullptr || obj_ref->sym->try_as<FunctionPtr>()) {
471472
std::string_view obj_type_name = obj_ref->get_identifier()->name;
472473
AnyTypeV obj_type_node = createV<ast_type_leaf_text>(obj_ref->loc, obj_type_name);
473474
if (obj_ref->has_instantiationTs()) { // Container<int>.create

0 commit comments

Comments
 (0)