Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase isFunctionCallExternal() precision by using InferType #171

Closed
blitz-1306 opened this issue Nov 22, 2022 · 0 comments · Fixed by #213
Closed

Increase isFunctionCallExternal() precision by using InferType #171

blitz-1306 opened this issue Nov 22, 2022 · 0 comments · Fixed by #213
Labels
debt Technical debt enhancement New feature or request

Comments

@blitz-1306
Copy link
Contributor

blitz-1306 commented Nov 22, 2022

export function isFunctionCallExternal(call: FunctionCall, inference: InferType): boolean {
    if (call.kind !== FunctionCallKind.FunctionCall) {
        return false;
    }

    if (
        call.vFunctionCallType === ExternalReferenceType.Builtin &&
        CALL_BUILTINS.includes(call.vFunctionName)
    ) {
        return true;
    }

    const exprT = inference.typeOf(call.vExpression);

    return exprT instanceof FunctionType && exprT.visibility === FunctionVisibility.External;
}

Above implementation would be more precise than pending implementation from #159, as it does not rely on typeString lookups.

However, implementing it as in above example is blocked due to failures of unit test. The exprT is resolved to a following:

FunctionType {
  id: 141,
  src: undefined,
  name: undefined,
  parameters: [],
  returns: [],
  visibility: 'public',
  mutability: 'nonpayable',
  implicitFirstArg: false
}

Here is the related Solidity sample:

contract Main {
    function c() public {}
    function d() public {}

    function main() public payable {
        (true ? this.c : this.d)();
    }
}

This sample is a shortened version of sample in external_calls.spec.ts integration test. The reason of failure is that it would need more time and efforts to investigate how to handle such expressions in typing context to figure out that the member access result is an external function (that is somehow done by compiler and reflected in typeString).

Current implementation seem to be fragile in edge-cases if we have struct with word external somewhere in the name, if also refered as an argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debt Technical debt enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant