everx-labs / TVM-Solidity-Compiler

Solidity compiler for TVM
GNU General Public License v3.0
125 stars 72 forks source link

Cannot compile contract with external function as callback. #36

Closed Pafaul closed 3 years ago

Pafaul commented 3 years ago

When you try to specify callback function and it's visibility is external, following error occures:

Error: Undeclared identifier. "testFunction" is not (or not yet) visible at this point.
  --> testContract.sol:12:59:
   |
12 |         CallbackTest(a).thisWillReturnSomething{callback: testFunction}(123);
   |                                                           ^^^^^^^^^^^^

Test contract:

pragma solidity >= 0.6.0;

import './TestInterface.sol';

contract SetCode { 
    uint c;
    constructor() public {
        tvm.accept();
    }

    function callExternalFunction(address a) external {
        CallbackTest(a).thisWillReturnSomething{callback: testFunction}(123);
    }

    function testFunction(uint b) external {
        c = b + b;
    }
}

Used test interface:

pragma solidity >= 0.6.0;

interface CallbackTest {
    function thisWillReturnSomething(uint param) external returns(uint);
}

Contract will compile if you change visibility of testFunction to public:

pragma solidity >= 0.6.0;

import './TestInterface.sol';

contract SetCode { 
    uint c;
    constructor() public {
        tvm.accept();
    }

    function callExternalFunction(address a) external {
        CallbackTest(a).thisWillReturnSomething{callback: testFunction}(123);
    }

    function testFunction(uint b) public {
        c = b + b;
    }
}
BorisI commented 3 years ago

Confirmed. To be fixed in the upcoming release.

SilkovAlexander commented 3 years ago

For external function you should use this.testFunction or SetCode.testFunction