Skip to content

Commit da8d854

Browse files
committed
fix second pass of method application arguments
1 parent 8232d42 commit da8d854

File tree

5 files changed

+45
-21
lines changed

5 files changed

+45
-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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
script;
22

33
use std::u128::*;
4+
use std::vec::*;
45

56
struct Data<T> {
67
value: T,
@@ -212,9 +213,21 @@ fn generic_impl_self_test() {
212213
assert(u.first.value + u.second.value == 7u8);
213214
}
214215

216+
impl<T> Vec<T> {
217+
pub fn with(self, with_value: T) -> Self {
218+
let mut inside_vec = self;
219+
inside_vec.push(with_value);
220+
inside_vec
221+
}
222+
}
223+
215224
fn main() -> u32 {
216225
generic_impl_self_test();
217226
result_impl_test();
218227

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

0 commit comments

Comments
 (0)