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

Cover arrays of generics in JSON ABI by handling their type arguments #2303

Merged
merged 5 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sway-core/src/type_engine/type_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ impl ToJsonAbi for TypeId {
name: "__array_element".to_string(),
type_field: type_id.json_abi_str(),
components: type_id.generate_json_abi(),
type_arguments: None,
type_arguments: type_id
.get_type_parameters()
.map(|v| v.iter().map(TypeParameter::generate_json_abi).collect()),
}]),
TypeInfo::Enum { variant_types, .. } => Some(
variant_types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,20 @@
],
"name": "__array_element",
"type": "struct MyStruct",
"typeArguments": null
"typeArguments": [
{
"components": null,
"name": "T",
"type": "u64",
"typeArguments": null
},
{
"components": null,
"name": "U",
"type": "bool",
"typeArguments": null
}
]
}
],
"name": "arg2",
Expand Down Expand Up @@ -156,5 +169,111 @@
}
],
"type": "function"
},
{
"inputs": [
{
"components": [
{
"components": [
{
"components": null,
"name": "__array_element",
"type": "u8",
"typeArguments": null
}
],
"name": "tim",
"type": "[u8; 3]",
"typeArguments": null
},
{
"components": [
{
"components": [
{
"components": null,
"name": "bim",
"type": "u8",
"typeArguments": null
},
{
"components": [
{
"components": null,
"name": "Foo",
"type": "u64",
"typeArguments": null
},
{
"components": null,
"name": "Bar",
"type": "bool",
"typeArguments": null
}
],
"name": "bam",
"type": "enum MyEnum",
"typeArguments": [
{
"components": null,
"name": "V",
"type": "u64",
"typeArguments": null
}
]
}
],
"name": "__array_element",
"type": "struct MyStruct",
"typeArguments": [
{
"components": null,
"name": "T",
"type": "u8",
"typeArguments": null
},
{
"components": null,
"name": "U",
"type": "u16",
"typeArguments": null
}
]
}
],
"name": "tam",
"type": "[struct MyStruct; 5]",
"typeArguments": null
}
],
"name": "arg",
"type": "struct MyArrayStruct",
"typeArguments": [
{
"components": null,
"name": "V",
"type": "u8",
"typeArguments": null
},
{
"components": null,
"name": "W",
"type": "u16",
"typeArguments": null
}
]
}
],
"name": "take_generic_array",
"outputs": [
{
"components": null,
"name": "",
"type": "u64",
"typeArguments": null
}
],
"type": "function"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ struct MyOtherStruct {
bom: u64,
}

struct MyArrayStruct<V, W> {
tim: [V;
3],
tam: [MyStruct<V,
W>;
5],
}

abi MyContract {
fn complex_function(arg1: MyStruct<[b256;
3], u8>, arg2: [MyStruct<u64, bool>;
4], arg3: (str[5], bool), arg3: MyOtherStruct, ) -> str[6];
fn take_generic_array(arg: MyArrayStruct<u8, u16>) -> u64;
}

impl MyContract for Contract {
Expand All @@ -24,4 +33,7 @@ impl MyContract for Contract {
4], arg3: (str[5], bool), arg4: MyOtherStruct, ) -> str[6] {
"fuel42"
}
fn take_generic_array(arg: MyArrayStruct<u8, u16>) -> u64 {
0
}
}