File tree Expand file tree Collapse file tree 3 files changed +35
-7
lines changed Expand file tree Collapse file tree 3 files changed +35
-7
lines changed Original file line number Diff line number Diff line change @@ -635,15 +635,16 @@ fn emit_expr(
635
635
} ,
636
636
637
637
Expr :: FuncCall ( func_call) => {
638
- // Emit the arguments first.
639
- for expr in func_call. args . iter ( ) {
640
- emit_expr ( ctx, ir, * expr, instr) ;
641
- }
642
-
638
+ // If this is method call, the target object (self or this in some
639
+ // programming languages) is the first argument.
643
640
if let Some ( obj) = func_call. object {
644
641
emit_expr ( ctx, ir, obj, instr) ;
645
642
}
646
-
643
+
644
+ for expr in func_call. args . iter ( ) {
645
+ emit_expr ( ctx, ir, * expr, instr) ;
646
+ }
647
+
647
648
if func_call. signature ( ) . result_may_be_undef {
648
649
emit_call_and_handle_undef (
649
650
ctx,
Original file line number Diff line number Diff line change
1
+ use std:: rc:: Rc ;
2
+
1
3
use crate :: modules:: prelude:: * ;
2
4
use crate :: modules:: protos:: test_proto2:: NestedProto2 ;
3
5
use crate :: modules:: protos:: test_proto2:: TestProto2 ;
4
6
use crate :: types:: Struct ;
5
- use std:: rc:: Rc ;
6
7
7
8
#[ cfg( test) ]
8
9
mod tests;
@@ -41,6 +42,25 @@ pub(crate) fn nested_method(
41
42
structure. field_by_name ( "nested_bool" ) . unwrap ( ) . type_value . as_bool ( )
42
43
}
43
44
45
+ #[ module_export(
46
+ name = "nested_method_with_arg" ,
47
+ method_of = "test_proto2.NestedProto2"
48
+ ) ]
49
+ pub ( crate ) fn nested_method_with_arg (
50
+ ctx : & mut ScanContext ,
51
+ structure : Rc < Struct > ,
52
+ arg : RuntimeString ,
53
+ ) -> bool {
54
+ let arg = arg. as_bstr ( ctx) ;
55
+ let field = structure
56
+ . field_by_name ( "nested_string" )
57
+ . unwrap ( )
58
+ . type_value
59
+ . as_string ( ) ;
60
+
61
+ arg. eq ( field. as_bstr ( ) )
62
+ }
63
+
44
64
#[ module_export]
45
65
pub ( crate ) fn undef_i64 ( _ctx : & mut ScanContext ) -> Option < i64 > {
46
66
None
@@ -126,6 +146,7 @@ fn main(data: &[u8], _meta: Option<&[u8]>) -> TestProto2 {
126
146
nested. set_nested_int32_one ( 1 ) ;
127
147
nested. set_nested_int64_one ( 1 ) ;
128
148
nested. set_nested_bool ( false ) ;
149
+ nested. set_nested_string ( "foo" . to_string ( ) ) ;
129
150
130
151
nested. nested_array_int64 . push ( 1 ) ;
131
152
nested. nested_array_int64 . push ( 10 ) ;
Original file line number Diff line number Diff line change @@ -266,6 +266,12 @@ fn test_proto2_module() {
266
266
"#
267
267
) ;
268
268
269
+ condition_true ! (
270
+ r#"
271
+ test_proto2.nested.nested_method_with_arg("foo")
272
+ "#
273
+ ) ;
274
+
269
275
condition_true ! (
270
276
r#"
271
277
not test_proto2.array_struct[0].nested_method()
You can’t perform that action at this time.
0 commit comments