From d4c23a92a6aa652b2f4bebd6562a1376059268f2 Mon Sep 17 00:00:00 2001 From: Calvin Baart Date: Wed, 10 Apr 2019 21:06:40 +0200 Subject: [PATCH 1/2] Fixed #416 --- src/Peachpie.Runtime/Dynamic/BinderHelpers.cs | 8 +++++++- tests/reflection/closure_allows_null_001.php | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/reflection/closure_allows_null_001.php diff --git a/src/Peachpie.Runtime/Dynamic/BinderHelpers.cs b/src/Peachpie.Runtime/Dynamic/BinderHelpers.cs index e8fd755f28..a052439a7f 100644 --- a/src/Peachpie.Runtime/Dynamic/BinderHelpers.cs +++ b/src/Peachpie.Runtime/Dynamic/BinderHelpers.cs @@ -29,7 +29,8 @@ public static bool IsImplicitParameter(this ParameterInfo p) return p.IsContextParameter() || p.IsQueryValueParameter() || p.IsLateStaticParameter() || - p.IsImportCallerClassParameter() || p.IsImportCallerStaticClassParameter(); + p.IsImportCallerClassParameter() || p.IsImportCallerStaticClassParameter() || + p.IsClosureParameter(); // TODO: classCtx, } @@ -67,6 +68,11 @@ public static bool IsImportCallerStaticClassParameter(this ParameterInfo p) p.GetCustomAttribute(typeof(ImportCallerStaticClassAttribute)) != null; } + public static bool IsClosureParameter(this ParameterInfo p) + { + return p.ParameterType == typeof(Closure) && p.Name == ""; + } + /// /// Gets value indicating the given type is of type Nullable<T>. /// diff --git a/tests/reflection/closure_allows_null_001.php b/tests/reflection/closure_allows_null_001.php new file mode 100644 index 0000000000..299189091d --- /dev/null +++ b/tests/reflection/closure_allows_null_001.php @@ -0,0 +1,15 @@ +getParameters()[0]; +$param2 = (new ReflectionFunction($tmp2))->getParameters()[0]; + +echo $param1->allowsNull() ? "true" : "false"; +echo $param2->allowsNull() ? "true" : "false"; \ No newline at end of file From d819b31e9ca00bc194bf867f3f9223526c0d8952 Mon Sep 17 00:00:00 2001 From: Calvin Baart Date: Wed, 10 Apr 2019 21:35:14 +0200 Subject: [PATCH 2/2] We still need to bind the Closure argument instead of skipping it --- src/Peachpie.Runtime/Dynamic/BinderHelpers.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Peachpie.Runtime/Dynamic/BinderHelpers.cs b/src/Peachpie.Runtime/Dynamic/BinderHelpers.cs index a052439a7f..f3685c798b 100644 --- a/src/Peachpie.Runtime/Dynamic/BinderHelpers.cs +++ b/src/Peachpie.Runtime/Dynamic/BinderHelpers.cs @@ -955,6 +955,11 @@ public static Expression BindToCall(Expression instance, MethodBase method, Expr { throw new NotSupportedException(); // we don't know current late static bound type } + else if (p.IsClosureParameter()) + { + boundargs[i] = args.BindArgument(argi, p); + argi++; + } else { throw new NotImplementedException();