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

Fix Handling of Higher-Order Functions #40

Merged
merged 1 commit into from
Sep 12, 2023

Conversation

dmzimmerman
Copy link
Contributor

@dmzimmerman dmzimmerman commented Mar 6, 2023

The current OCaml-Solidity parser does not properly handle the use of higher-order functions. For example, given this code:

contract A {
    uint256 internal a;

    function accessibleInternally(int256 b) public {
        b = b + 1;
    }

    function hof(function(int256) somfunc, int256 a) internal {
        a = a + 1;
    }

    function useHof() public {
        hof(accessibleInternally, 10);
        a = 1 + 1;
    }
}

it returns the following error: Type error: Invalid type for argument in "function call". Invalid implicit conversion from "function(int256) nonpayable " to "function(int256) nonpayable " requested. This is because it doesn't realize that a public function is an acceptable substitute for the internal function expected as a parameter to hof.

This PR fixes this issue (and other similar type conversion issues) with higher-order functions by implementing the allowed conversions for function types and mutabilities; it also includes several test cases to exercise the functionality.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@ddeclerck ddeclerck self-assigned this Apr 24, 2023
@ddeclerck ddeclerck self-requested a review April 24, 2023 12:10
@dmzimmerman
Copy link
Contributor Author

I'm not sure why it thinks I haven't signed the CLA; I signed it for the other PR (and just went through it again now).

@ddeclerck ddeclerck closed this Sep 12, 2023
@ddeclerck ddeclerck reopened this Sep 12, 2023
@ddeclerck ddeclerck merged commit 27eed7b into OCamlPro:master Sep 12, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants