Skip to content

Commit ba8951e

Browse files
esdrubaltritao
andauthored
Fixes ContractCaller type propagation. (#6662)
## 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>
1 parent 40e2b30 commit ba8951e

File tree

6 files changed

+51
-6
lines changed

6 files changed

+51
-6
lines changed

sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,14 +1780,10 @@ impl ty::TyExpression {
17801780
// type check the address and make sure it is
17811781
let err_span = address.span().clone();
17821782
let address_expr = {
1783-
// We want to type check the address expression as we do in the second pass, otherwise we get
1784-
// mismatched types while comparing TypeInfo::ContractCaller which is the return type of
1785-
// TyExpressionVariant::AbiCast.
17861783
let ctx = ctx
17871784
.by_ref()
17881785
.with_help_text("An address that is being ABI cast must be of type b256")
1789-
.with_type_annotation(type_engine.insert(engines, TypeInfo::B256, None))
1790-
.with_code_block_first_pass(false);
1786+
.with_type_annotation(type_engine.insert(engines, TypeInfo::B256, None));
17911787
ty::TyExpression::type_check(handler, ctx, address)
17921788
.unwrap_or_else(|err| ty::TyExpression::error(err, err_span, engines))
17931789
};

sway-core/src/type_system/info.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,11 @@ impl PartialEqWithEngines for TypeInfo {
379379
abi_name: r_abi_name,
380380
address: r_address,
381381
},
382-
) => l_abi_name == r_abi_name && l_address.as_deref().eq(&r_address.as_deref(), ctx),
382+
) => {
383+
let l_address_span = l_address.as_ref().map(|x| x.span.clone());
384+
let r_address_span = r_address.as_ref().map(|x| x.span.clone());
385+
l_abi_name == r_abi_name && l_address_span == r_address_span
386+
}
383387
(Self::Array(l0, l1), Self::Array(r0, r1)) => {
384388
((l0.type_id == r0.type_id)
385389
|| type_engine
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[package]]
2+
name = "abi_cast_nested_method"
3+
source = "member"
4+
dependencies = ["std"]
5+
6+
[[package]]
7+
name = "core"
8+
source = "path+from-root-0D81C4DB888BC505"
9+
10+
[[package]]
11+
name = "std"
12+
source = "path+from-root-0D81C4DB888BC505"
13+
dependencies = ["core"]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
authors = ["Fuel Labs <contact@fuel.sh>"]
3+
entry = "main.sw"
4+
license = "Apache-2.0"
5+
name = "abi_cast_nested_method"
6+
implicit-std = false
7+
8+
[dependencies]
9+
std = { path = "../../../../../../../sway-lib-std" }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
script;
2+
3+
abi AMM {
4+
fn pool() -> Option<ContractId>;
5+
}
6+
abi Exchange {
7+
fn swap_exact_output();
8+
}
9+
10+
fn main() {
11+
let amm_contract = abi(AMM, 0x0000000000000000000000000000000000000000000000000000000000000000);
12+
13+
let exchange_contract_id = amm_contract.pool();
14+
15+
// let a = exchange_contract_id.unwrap().into();
16+
// let exchange_contract = abi(Exchange, a);
17+
18+
let exchange_contract = abi(Exchange, exchange_contract_id.unwrap().into());
19+
20+
exchange_contract.swap_exact_output();
21+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
category = "compile"
2+
expected_warnings = 0

0 commit comments

Comments
 (0)