@@ -51,13 +51,8 @@ public IValue CallMethod(IBslProcess process, IRuntimeContextInstance target, st
5151 var methodIdx = target . GetMethodNumber ( methodName ) ;
5252 var methInfo = target . GetMethodInfo ( methodIdx ) ;
5353
54- IValue [ ] argsToPass ;
55- if ( target . DynamicMethodSignatures )
56- argsToPass = arguments ? . ToArray ( ) ?? [ ] ;
57- else
58- argsToPass = GetArgsToPass ( arguments , methInfo . CallParameters ) ;
59-
60-
54+ var argsToPass = target . DynamicMethodSignatures ? GetArgsToPass ( arguments ) : GetArgsToPass ( arguments , methInfo . CallParameters ) ;
55+
6156 IValue retValue = BslUndefinedValue . Instance ;
6257 if ( methInfo . IsFunction ( ) )
6358 {
@@ -71,6 +66,21 @@ public IValue CallMethod(IBslProcess process, IRuntimeContextInstance target, st
7166 return retValue ;
7267 }
7368
69+ // в динамические методы все параметры будут переданы как переменные-ссылки на элементы массива аргументов
70+ // это дает возможность возвращать значения через параметры
71+ // ответственность за неизменность параметров, передаваемых по значению, - на вызываемом методе
72+ private static IValue [ ] GetArgsToPass ( ArrayImpl arguments )
73+ {
74+ var argsToPass = new IValue [ arguments ? . Count ( ) ?? 0 ] ;
75+
76+ for ( int i = 0 ; i < argsToPass . Length ; ++ i )
77+ {
78+ argsToPass [ i ] = Variable . CreateIndexedPropertyReference ( arguments , ValueFactory . Create ( i ) , "$argref" ) ;
79+ }
80+
81+ return argsToPass ;
82+ }
83+
7484 private static IValue [ ] GetArgsToPass ( ArrayImpl arguments , ReadOnlySpan < BslCallParameter > parameters )
7585 {
7686 var argValues = arguments ? . ToArray ( ) ?? [ ] ;
0 commit comments