Skip to content

Produce valid syntax for function type params #77

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

Merged
merged 1 commit into from
Jul 17, 2022
Merged

Conversation

gnidan
Copy link
Owner

@gnidan gnidan commented Jul 17, 2022

Addresses #76, originally raised by @esaulpaugh.

This PR ensures the resulting Solidity output for function type parameters will always be valid.

In cases where the internalType field is provided, this change uses that field directly for best results. Since that field is not part of the ABI JSON spec, then in cases where it's not provided, this PR falls back to behavior of specifying the minimally-valid function() external type alongside a warning.

Example missing `internalType` fallback output
// SPDX-License-Identifier: UNLICENSED
// !! THIS FILE WAS AUTOGENERATED BY abi-to-sol v0.6.2. SEE SOURCE BELOW. !!
pragma solidity >=0.7.0 <0.9.0;

interface MyInterface {
    function map(
        /* warning: the following type may be incomplete. the receiving contract may expect additional input or output parameters. */
        function() f,
        uint256[] memory list
    ) external pure returns (uint256[] memory);
}

// THIS FILE WAS AUTOGENERATED FROM THE FOLLOWING ABI JSON:
/*
[{"inputs":[{"name":"f","type":"function"},{"internalType":"uint256[]","name":"list","type":"uint256[]"}],"name":"map","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"pure","type":"function"}]
*/

Use the `internalType` field directly if it's provided.

In cases where this is not provided, output minimally syntactically
valid syntax with a warning comment.
@gnidan gnidan merged commit 386d599 into develop Jul 17, 2022
@gnidan gnidan deleted the function-types branch July 17, 2022 03:47
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.

1 participant