Skip to content

Commit 439f935

Browse files
authored
fix second pass of method application arguments (#6526)
## Description This PR fixes #6487. ## 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. - [ ] 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.
1 parent 09a992f commit 439f935

File tree

5 files changed

+46
-21
lines changed

5 files changed

+46
-21
lines changed

sway-core/src/language/ty/expression/expression_variant.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,9 @@ impl TypeCheckAnalysis for TyExpressionVariant {
10071007
) -> Result<(), ErrorEmitted> {
10081008
match self {
10091009
TyExpressionVariant::Literal(_) => {}
1010-
TyExpressionVariant::FunctionApplication { fn_ref, .. } => {
1010+
TyExpressionVariant::FunctionApplication {
1011+
fn_ref, arguments, ..
1012+
} => {
10111013
let fn_decl_id = ctx.get_normalized_fn_node_id(fn_ref.id());
10121014

10131015
let fn_node = ctx.get_node_for_fn_decl(&fn_decl_id);
@@ -1021,6 +1023,22 @@ impl TypeCheckAnalysis for TyExpressionVariant {
10211023
let _ = fn_decl_id.type_check_analyze(handler, ctx);
10221024
}
10231025
}
1026+
1027+
// Unify arguments that are still not concrete
1028+
let decl = ctx.engines.de().get(fn_ref.id());
1029+
1030+
use crate::type_system::unify::unifier::*;
1031+
let unifier = Unifier::new(ctx.engines, "", UnifyKind::Default);
1032+
1033+
for (decl_param, arg) in decl.parameters.iter().zip(arguments.iter()) {
1034+
unifier.unify(
1035+
handler,
1036+
arg.1.return_type,
1037+
decl_param.type_argument.type_id,
1038+
&Span::dummy(),
1039+
false,
1040+
);
1041+
}
10241042
}
10251043
TyExpressionVariant::LazyOperator { lhs, rhs, .. } => {
10261044
lhs.type_check_analyze(handler, ctx)?;

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,7 @@ pub(crate) fn type_check_method_application(
5252
let arg_handler = Handler::default();
5353
let arg_opt = ty::TyExpression::type_check(&arg_handler, ctx, arg).ok();
5454

55-
// Check this type needs a second pass
56-
let has_errors = arg_handler.has_errors();
57-
let is_not_concrete = arg_opt
58-
.as_ref()
59-
.map(|x| {
60-
x.return_type
61-
.extract_inner_types(engines, IncludeSelf::Yes)
62-
.iter()
63-
.any(|x| !x.is_concrete(engines, TreatNumericAs::Abstract))
64-
})
65-
.unwrap_or_default();
66-
let needs_second_pass = has_errors || is_not_concrete;
55+
let needs_second_pass = arg_handler.has_errors();
6756

6857
if index == 0 {
6958
// We want to emit errors in the self parameter and ignore TraitConstraintNotSatisfied with Placeholder
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
[[package]]
2-
name = 'core'
3-
source = 'path+from-root-DA3FEDB2AB26E552'
2+
name = "core"
3+
source = "path+from-root-DA3FEDB2AB26E552"
44

55
[[package]]
6-
name = 'generic_impl_self'
7-
source = 'member'
8-
dependencies = ['std']
6+
name = "generic_impl_self"
7+
source = "member"
8+
dependencies = [
9+
"core",
10+
"std",
11+
]
912

1013
[[package]]
11-
name = 'std'
12-
source = 'path+from-root-DA3FEDB2AB26E552'
13-
dependencies = ['core']
14+
name = "std"
15+
source = "path+from-root-DA3FEDB2AB26E552"
16+
dependencies = ["core"]

test/src/e2e_vm_tests/test_programs/should_pass/language/generic_impl_self/Forc.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ name = "generic_impl_self"
55
entry = "main.sw"
66

77
[dependencies]
8+
core = { path = "../../../../../../../sway-lib-core" }
89
std = { path = "../../../../../../../sway-lib-std" }

test/src/e2e_vm_tests/test_programs/should_pass/language/generic_impl_self/src/main.sw

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,23 @@ fn generic_impl_self_test() {
212212
assert(u.first.value + u.second.value == 7u8);
213213
}
214214

215+
use std::vec::*;
216+
217+
impl<T> Vec<T> {
218+
pub fn with(self, with_value: T) -> Self {
219+
let mut inside_vec = self;
220+
inside_vec.push(with_value);
221+
inside_vec
222+
}
223+
}
224+
215225
fn main() -> u32 {
216226
generic_impl_self_test();
217227
result_impl_test();
218228

229+
// data must be Vec<u256>
230+
let data = Vec::new().with(0x333u256).with(0x222u256);
231+
assert(data.len() == 2);
232+
219233
10u32
220234
}

0 commit comments

Comments
 (0)