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(sol-macro): namespaced custom type resolution #731

Merged
merged 2 commits into from
Sep 9, 2024

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Sep 7, 2024

Motivation

Currently type resolution does not handle namespaces correctly, causing such example to fail:

alloy_sol_types::sol! {
    library LibA {
        struct B {
            uint256 val;
        }

        struct A {
            B val;
        }
    }

    library LibB {
        struct Nested {
            uint256 val1;
            LibA.A val2;
        }
    }

    contract A {
        function get_val(LibB.Nested memory user) external;
    }
}

When resolving LibB.Nested we'll enter LibA.A type which contains B struct. However, we don't set namespace to LibA, and will instead try to resolve B as item of LibB, which would fail.

Solution

I've updated resolve_custom_types fn to use custom Resolver visitor which keeps track of namespace, updates it before entering a type from another namespace and resets it to previous value after type is processed.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@DaniPopes DaniPopes merged commit 1ff30e2 into main Sep 9, 2024
31 checks passed
@DaniPopes DaniPopes deleted the klkvr/fix-type-resolution branch September 9, 2024 09:48
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.

2 participants