Skip to content

Commit

Permalink
properly convert IPhpArray
Browse files Browse the repository at this point in the history
IPhpArray was treated as object causing multiple implicit conversion issues
  • Loading branch information
jakubmisek committed Sep 13, 2024
1 parent bfb8a4f commit 0dbb1b0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/Peachpie.CodeAnalysis/CodeGen/CodeGenerator.Convert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
16 changes: 13 additions & 3 deletions src/Peachpie.CodeAnalysis/Semantics/Conversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

//
Expand Down
3 changes: 2 additions & 1 deletion src/Peachpie.CodeAnalysis/Symbols/CoreMembers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/Peachpie.CodeAnalysis/Symbols/TypeSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0dbb1b0

Please sign in to comment.