diff --git a/src/Peachpie.CodeAnalysis/CodeGen/CodeGenerator.Convert.cs b/src/Peachpie.CodeAnalysis/CodeGen/CodeGenerator.Convert.cs index f2d2b6e543..76ddb406ac 100644 --- a/src/Peachpie.CodeAnalysis/CodeGen/CodeGenerator.Convert.cs +++ b/src/Peachpie.CodeAnalysis/CodeGen/CodeGenerator.Convert.cs @@ -96,7 +96,15 @@ public TypeSymbol EmitConvertToPhpValue(TypeSymbol from, TypeRefMask fromHint) if (from.IsReferenceType) { - EmitCall(ILOpCode.Call, CoreMethods.PhpValue.FromClass_Object).Expect(CoreTypes.PhpValue); + if (from.Is_IPhpArray()) // Blob or PhpArray + { + EmitCall(ILOpCode.Call, CoreMethods.PhpValue.Create_IPhpArray).Expect(CoreTypes.PhpValue); + } + else + { + Debug.Assert(!Conversions.IsSpecialReferenceType(from)); + EmitCall(ILOpCode.Call, CoreMethods.PhpValue.FromClass_Object).Expect(CoreTypes.PhpValue); + } } else if (from.SpecialType == SpecialType.System_Void) { diff --git a/src/Peachpie.CodeAnalysis/Semantics/Conversions.cs b/src/Peachpie.CodeAnalysis/Semantics/Conversions.cs index 39a8f206ac..b400a2f54c 100644 --- a/src/Peachpie.CodeAnalysis/Semantics/Conversions.cs +++ b/src/Peachpie.CodeAnalysis/Semantics/Conversions.cs @@ -434,10 +434,20 @@ public static bool IsSpecialReferenceType(TypeSymbol t) MethodSymbol TryWellKnownImplicitConversion(TypeSymbol from, TypeSymbol to) { // Object -> PhpValue - if (to == _compilation.CoreTypes.PhpValue && from.IsReferenceType && !IsSpecialReferenceType(from)) + if (to == _compilation.CoreTypes.PhpValue) { - // expecting the object to be a class instance - return _compilation.CoreMethods.PhpValue.FromClass_Object; + if (from.IsReferenceType && !IsSpecialReferenceType(from)) + { + if (from.Is_IPhpArray()) // Blob or PhpArray + { + return _compilation.CoreMethods.PhpValue.Create_IPhpArray; + } + else + { + // expecting the object to be a class instance + return _compilation.CoreMethods.PhpValue.FromClass_Object; + } + } } // diff --git a/src/Peachpie.CodeAnalysis/Symbols/CoreMembers.cs b/src/Peachpie.CodeAnalysis/Symbols/CoreMembers.cs index 532db57947..fe36d24a79 100644 --- a/src/Peachpie.CodeAnalysis/Symbols/CoreMembers.cs +++ b/src/Peachpie.CodeAnalysis/Symbols/CoreMembers.cs @@ -580,6 +580,7 @@ public PhpValueHolder(CoreTypes ct) Create_PhpString = ct.PhpValue.Method("Create", ct.PhpString); Create_PhpNumber = ct.PhpValue.Method("Create", ct.PhpNumber); Create_PhpArray = ct.PhpValue.Method("Create", ct.PhpArray); + Create_IPhpArray = ct.PhpValue.Method("Create", ct.IPhpArray); Create_PhpAlias = ct.PhpValue.Method("Create", ct.PhpAlias); Create_IntStringKey = ct.PhpValue.Method("Create", ct.IntStringKey); @@ -598,7 +599,7 @@ public readonly CoreMethod DeepCopy, GetValue, Eq_PhpValue_PhpValue, Eq_PhpValue_String, Eq_String_PhpValue, Ineq_PhpValue_PhpValue, Ineq_PhpValue_String, Ineq_String_PhpValue, - Create_Boolean, Create_Long, Create_Int, Create_Double, Create_String, Create_PhpString, Create_PhpNumber, Create_PhpAlias, Create_PhpArray, Create_IntStringKey, + Create_Boolean, Create_Long, Create_Int, Create_Double, Create_String, Create_PhpString, Create_PhpNumber, Create_PhpAlias, Create_PhpArray, Create_IPhpArray, Create_IntStringKey, FromClr_Object, FromClass_Object, FromStruct_T; public readonly CoreField diff --git a/src/Peachpie.CodeAnalysis/Symbols/TypeSymbolExtensions.cs b/src/Peachpie.CodeAnalysis/Symbols/TypeSymbolExtensions.cs index 5befe4527b..83e3fbdd79 100644 --- a/src/Peachpie.CodeAnalysis/Symbols/TypeSymbolExtensions.cs +++ b/src/Peachpie.CodeAnalysis/Symbols/TypeSymbolExtensions.cs @@ -112,6 +112,11 @@ public static bool Is_PhpArray(this ITypeSymbol t) return t.MetadataName == "PhpArray" && (t.ContainingAssembly as AssemblySymbol)?.IsPeachpieCorLibrary == true; } + public static bool Is_IPhpArray(this ITypeSymbol t) + { + return t.MetadataName == "IPhpArray" && (t.ContainingAssembly as AssemblySymbol)?.IsPeachpieCorLibrary == true; + } + public static bool Is_PhpResource(this ITypeSymbol t) { return t.MetadataName == "PhpResource" && (t.ContainingAssembly as AssemblySymbol)?.IsPeachpieCorLibrary == true;