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

Typegen fails when handling Sway type aliases #3073

Closed
petertonysmith94 opened this issue Sep 2, 2024 · 7 comments · Fixed by #3066
Closed

Typegen fails when handling Sway type aliases #3073

petertonysmith94 opened this issue Sep 2, 2024 · 7 comments · Fixed by #3066
Assignees
Labels
bug Issue is a bug

Comments

@petertonysmith94
Copy link
Contributor

petertonysmith94 commented Sep 2, 2024

Summary

We can define alias types in Sway. These are getting incorrectly transpiled and therefore causing the following error while running typegen:

FuelError: Type not supported: (struct std::asset_id::AssetId, struct std::asset_id::AssetId, bool)

Incoming from the forum.

Example

Consider the following contract:

type TupleWithNativeAssets = (AssetId, AssetId, bool);

abi MyContract {
    fn alias_types_tuple_with_native_types(x: TupleWithNativeAssets) -> TupleWithNativeAssets;
}

The following transpile ABI is produced:

{
  "types": [
    {
      "typeId": 1,
      // This type is incorrect
      "type": "(struct std::asset_id::AssetId, struct std::asset_id::AssetId, bool)",
      "components": [
        {
          "name": "__tuple_element",
          "type": 22,
          "typeArguments": null
        },
        {
          "name": "__tuple_element",
          "type": 22,
          "typeArguments": null
        },
        {
          "name": "__tuple_element",
          "type": 32,
          "typeArguments": null
        }
      ],
      "typeParameters": null
    },
  ],
  "functions": [
    {
      "inputs": [
        {
          "name": "x",
          "type": 1,
          "typeArguments": null
        }
      ],
      "name": "alias_types_tuple_with_native_types",
      // ...
    },
  ]
  // ...
}

Expected

We expect to generate a type with signature:
(_, _, _)

Actual

We actually generate a type with signature:
(struct std::asset_id::AssetId, struct std::asset_id::AssetId, bool)

@petertonysmith94 petertonysmith94 added the bug Issue is a bug label Sep 2, 2024
@petertonysmith94 petertonysmith94 self-assigned this Sep 2, 2024
@petertonysmith94
Copy link
Contributor Author

petertonysmith94 commented Sep 2, 2024

It appears this is potentially an issue with forc rather than the transpiler - more to follow.

From my investigation, I've created the following issue in Sway:

@petertonysmith94 petertonysmith94 changed the title Sway type aliases transpired incorrectly Typegen fails when handling Sway type aliases Sep 2, 2024
@petertonysmith94
Copy link
Contributor Author

Closed as this appears to be an issue in Sway:

@arboleya
Copy link
Member

arboleya commented Sep 5, 2024

@petertonysmith94 Should we add some tests to validate this? They will fail at first, but they'll pass once I merge this:

The issue (FuelLabs/sway#6494) was fixed in the latest forc:

@petertonysmith94
Copy link
Contributor Author

@arboleya We have tests here for an aliased type.

@arboleya
Copy link
Member

arboleya commented Sep 6, 2024

Great! Can we merge these tests, then?

@petertonysmith94
Copy link
Contributor Author

I've based off of:

This is ready to go once we merge the above:

@arboleya
Copy link
Member

arboleya commented Sep 6, 2024

Thank you! 🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants