Skip to content

Commit b3aff57

Browse files
committed
runtime call with ReadOnlySpan params to Array params
test: anonymous_006_args
1 parent 9c63555 commit b3aff57

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Peachpie.Runtime/Dynamic/BinderHelpers.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,19 @@ public static Expression BindToCall(Expression instance, MethodBase method, Expr
13041304

13051305
if (i == ps.Length - 1 && p.IsParamsParameter(out var elementType))
13061306
{
1307-
boundargs[i] = Expression.Convert(args.BindParamsArray(argi, elementType), p.ParameterType);
1307+
var arg = args.BindParamsArray(argi, elementType);
1308+
if (arg.Type != p.ParameterType)
1309+
{
1310+
// ReadOnlySpan -> Array
1311+
if (arg.Type.IsGenericType && arg.Type.GetGenericTypeDefinition() == typeof(ReadOnlySpan<>) && p.ParameterType.IsArray)
1312+
{
1313+
arg = Expression.Call(
1314+
arg,
1315+
arg.Type.GetMethod(nameof(ReadOnlySpan<PhpValue>.ToArray))
1316+
);
1317+
}
1318+
}
1319+
boundargs[i] = Expression.Convert(arg, p.ParameterType);
13081320
}
13091321
else
13101322
{

src/Peachpie.Runtime/Dynamic/OverloadBinder.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ protected ArgumentsBinder(Expression ctx)
286286

287287
/// <summary>
288288
/// Bind arguments to array of parameters.
289+
/// Can return expression with element_type[] or ReadOnlySpan&lt;element_type&gt;
289290
/// </summary>
290291
public abstract Expression BindParamsArray(int fromarg, Type element_type);
291292

@@ -460,6 +461,8 @@ public ArgsSpanBinder(Expression ctx, Expression argsarray)
460461
_argsarray = argsarray;
461462
}
462463

464+
public Type ElementType => _argsarray.Type.GenericTypeArguments[0];
465+
463466
public override Expression BindArgsCount()
464467
{
465468
if (_lazyArgc == null)
@@ -565,8 +568,12 @@ public override Expression BindWriteBack(int targetarg, Expression expression)
565568

566569
public override Expression BindParamsArray(int fromarg, Type element_type)
567570
{
568-
//if (element_type == _argsarray.Type.GetElementType())
569-
//if (true)
571+
var array_element_type = this.ElementType; // PhpValue always
572+
if (array_element_type != element_type)
573+
{
574+
throw new NotImplementedException();
575+
}
576+
570577
if (fromarg == 0)
571578
{
572579
return _argsarray;

0 commit comments

Comments
 (0)