Skip to content

Commit

Permalink
Fixes struct and enum call path comparison to use suffix. (FuelLabs#4133
Browse files Browse the repository at this point in the history
)

## Description
The issue is that currently call paths of structs and enums are based on
module path which can differ depending on the order of imports.

The solution was to revert to the old behavior of comparing only the
type name contained in the suffix.

Closes FuelLabs#4125

## Checklist

- [x] I have linked to any relevant issues.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

Co-authored-by: Mohammad Fawaz <[email protected]>
  • Loading branch information
esdrubal and mohammadfawaz authored Feb 20, 2023
1 parent 8bef89c commit 72503fc
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 3 deletions.
4 changes: 2 additions & 2 deletions sway-core/src/type_system/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl PartialEqWithEngines for TypeInfo {
type_parameters: r_type_parameters,
},
) => {
l_name == r_name
l_name.suffix == r_name.suffix
&& l_variant_types.eq(r_variant_types, engines)
&& l_type_parameters.eq(r_type_parameters, engines)
}
Expand All @@ -280,7 +280,7 @@ impl PartialEqWithEngines for TypeInfo {
type_parameters: r_type_parameters,
},
) => {
l_name == r_name
l_name.suffix == r_name.suffix
&& l_fields.eq(r_fields, engines)
&& l_type_parameters.eq(r_type_parameters, engines)
}
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/type_system/unify_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'a> UnifyCheck<'a> {
.iter()
.map(|x| x.type_id)
.collect::<Vec<_>>();
l_name == r_name && self.check_multiple(&l_types, &r_types)
l_name.suffix == r_name.suffix && self.check_multiple(&l_types, &r_types)
}
// Let empty enums to coerce to any other type. This is useful for Never enum.
(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[package]]
name = 'core'
source = 'path+from-root-B1BD953F42F45255'

[[package]]
name = 'return_struct'
source = 'member'
dependencies = ['std']

[[package]]
name = 'std'
source = 'path+from-root-B1BD953F42F45255'
dependencies = ['core']
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
license = "Apache-2.0"
name = "return_struct"
entry = "main.sw"

[dependencies]
std = { path = "../../../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"configurables": [],
"functions": [
{
"attributes": [
{
"arguments": [
"read"
],
"name": "storage"
}
],
"inputs": [],
"name": "test_function",
"output": {
"name": "",
"type": 1,
"typeArguments": [
{
"name": "",
"type": 3,
"typeArguments": null
}
]
}
}
],
"loggedTypes": [],
"messagesTypes": [],
"types": [
{
"components": [],
"type": "()",
"typeId": 0,
"typeParameters": null
},
{
"components": [
{
"name": "None",
"type": 0,
"typeArguments": null
},
{
"name": "Some",
"type": 2,
"typeArguments": null
}
],
"type": "enum Option",
"typeId": 1,
"typeParameters": [
2
]
},
{
"components": null,
"type": "generic T",
"typeId": 2,
"typeParameters": null
},
{
"components": [],
"type": "struct MyStruct",
"typeId": 3,
"typeParameters": null
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library data_structures;

pub struct MyStruct {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
library interface;

dep data_structures;

use data_structures::MyStruct;

abi MyContract {
#[storage(read)]
fn test_function() -> Option<MyStruct>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
contract;

dep interface;
dep data_structures;

use interface::MyContract;
use data_structures::MyStruct;

storage {
a: StorageMap<u64, MyStruct> = StorageMap {}
}

impl MyContract for Contract {
#[storage(read)]
fn test_function() -> Option<MyStruct> {
storage.a.get(1)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
category = "compile"
validate_abi = true

0 comments on commit 72503fc

Please sign in to comment.