Skip to content

Commit

Permalink
Fixes ContractCaller type propagation. (#6662)
Browse files Browse the repository at this point in the history
## Description

ContractCaller comparison was too restrictive, we now just check if the
span matches. This fixes unification of codeblock first pass variables
with second pass variables.

Fixes [#6614](#6614)

## Checklist

- [x] I have linked to any relevant issues.
- [x] 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).
- [ ] If my change requires substantial documentation changes, I have
[requested support from the DevRel
team](https://github.com/FuelLabs/devrel-requests/issues/new/choose)
- [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: João Matos <joao@tritao.eu>
  • Loading branch information
esdrubal and tritao authored Oct 23, 2024
1 parent 40e2b30 commit ba8951e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1780,14 +1780,10 @@ impl ty::TyExpression {
// type check the address and make sure it is
let err_span = address.span().clone();
let address_expr = {
// We want to type check the address expression as we do in the second pass, otherwise we get
// mismatched types while comparing TypeInfo::ContractCaller which is the return type of
// TyExpressionVariant::AbiCast.
let ctx = ctx
.by_ref()
.with_help_text("An address that is being ABI cast must be of type b256")
.with_type_annotation(type_engine.insert(engines, TypeInfo::B256, None))
.with_code_block_first_pass(false);
.with_type_annotation(type_engine.insert(engines, TypeInfo::B256, None));
ty::TyExpression::type_check(handler, ctx, address)
.unwrap_or_else(|err| ty::TyExpression::error(err, err_span, engines))
};
Expand Down
6 changes: 5 additions & 1 deletion sway-core/src/type_system/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ impl PartialEqWithEngines for TypeInfo {
abi_name: r_abi_name,
address: r_address,
},
) => l_abi_name == r_abi_name && l_address.as_deref().eq(&r_address.as_deref(), ctx),
) => {
let l_address_span = l_address.as_ref().map(|x| x.span.clone());
let r_address_span = r_address.as_ref().map(|x| x.span.clone());
l_abi_name == r_abi_name && l_address_span == r_address_span
}
(Self::Array(l0, l1), Self::Array(r0, r1)) => {
((l0.type_id == r0.type_id)
|| type_engine
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[package]]
name = "abi_cast_nested_method"
source = "member"
dependencies = ["std"]

[[package]]
name = "core"
source = "path+from-root-0D81C4DB888BC505"

[[package]]
name = "std"
source = "path+from-root-0D81C4DB888BC505"
dependencies = ["core"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "abi_cast_nested_method"
implicit-std = false

[dependencies]
std = { path = "../../../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
script;

abi AMM {
fn pool() -> Option<ContractId>;
}
abi Exchange {
fn swap_exact_output();
}

fn main() {
let amm_contract = abi(AMM, 0x0000000000000000000000000000000000000000000000000000000000000000);

let exchange_contract_id = amm_contract.pool();

// let a = exchange_contract_id.unwrap().into();
// let exchange_contract = abi(Exchange, a);

let exchange_contract = abi(Exchange, exchange_contract_id.unwrap().into());

exchange_contract.swap_exact_output();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
category = "compile"
expected_warnings = 0

0 comments on commit ba8951e

Please sign in to comment.