File tree Expand file tree Collapse file tree 5 files changed +45
-21
lines changed
semantic_analysis/ast_node/expression/typed_expression
test/src/e2e_vm_tests/test_programs/should_pass/language/generic_impl_self Expand file tree Collapse file tree 5 files changed +45
-21
lines changed Original file line number Diff line number Diff line change @@ -1007,7 +1007,9 @@ impl TypeCheckAnalysis for TyExpressionVariant {
1007
1007
) -> Result < ( ) , ErrorEmitted > {
1008
1008
match self {
1009
1009
TyExpressionVariant :: Literal ( _) => { }
1010
- TyExpressionVariant :: FunctionApplication { fn_ref, .. } => {
1010
+ TyExpressionVariant :: FunctionApplication {
1011
+ fn_ref, arguments, ..
1012
+ } => {
1011
1013
let fn_decl_id = ctx. get_normalized_fn_node_id ( fn_ref. id ( ) ) ;
1012
1014
1013
1015
let fn_node = ctx. get_node_for_fn_decl ( & fn_decl_id) ;
@@ -1021,6 +1023,22 @@ impl TypeCheckAnalysis for TyExpressionVariant {
1021
1023
let _ = fn_decl_id. type_check_analyze ( handler, ctx) ;
1022
1024
}
1023
1025
}
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
+ }
1024
1042
}
1025
1043
TyExpressionVariant :: LazyOperator { lhs, rhs, .. } => {
1026
1044
lhs. type_check_analyze ( handler, ctx) ?;
Original file line number Diff line number Diff line change @@ -52,18 +52,7 @@ pub(crate) fn type_check_method_application(
52
52
let arg_handler = Handler :: default ( ) ;
53
53
let arg_opt = ty:: TyExpression :: type_check ( & arg_handler, ctx, arg) . ok ( ) ;
54
54
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 ( ) ;
67
56
68
57
if index == 0 {
69
58
// We want to emit errors in the self parameter and ignore TraitConstraintNotSatisfied with Placeholder
Original file line number Diff line number Diff line change 1
1
[[package]]
2
- name = ' core'
3
- source = ' path+from-root-DA3FEDB2AB26E552'
2
+ name = " core"
3
+ source = " path+from-root-DA3FEDB2AB26E552"
4
4
5
5
[[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
+ ]
9
12
10
13
[[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" ]
Original file line number Diff line number Diff line change @@ -5,4 +5,5 @@ name = "generic_impl_self"
5
5
entry = " main.sw"
6
6
7
7
[dependencies ]
8
+ core = { path = " ../../../../../../../sway-lib-core" }
8
9
std = { path = " ../../../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change 1
1
script ;
2
2
3
3
use std :: u128 :: * ;
4
+ use std :: vec :: * ;
4
5
5
6
struct Data <T > {
6
7
value : T ,
@@ -212,9 +213,21 @@ fn generic_impl_self_test() {
212
213
assert (u . first. value + u . second. value == 7u8 );
213
214
}
214
215
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
+
215
224
fn main () -> u32 {
216
225
generic_impl_self_test ();
217
226
result_impl_test ();
218
227
228
+ // data must be Vec<u256>
229
+ let data = Vec :: new (). with (0x333u256 ). with (0x222u256 );
230
+ assert (data . len () == 2 );
231
+
219
232
10u32
220
233
}
You can’t perform that action at this time.
0 commit comments