IPhpArray was treated as object causing multiple implicit conversion issues
This commit is contained in:
Jakub Míšek 2024-09-13 15:51:38 +02:00
Родитель bfb8a4f764
Коммит 0dbb1b0a21
4 изменённых файлов: 29 добавлений и 5 удалений

Просмотреть файл

@ -96,7 +96,15 @@ namespace Pchp.CodeAnalysis.CodeGen
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)
{

Просмотреть файл

@ -434,10 +434,20 @@ namespace Pchp.CodeAnalysis.Semantics
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;
}
}
}
//

Просмотреть файл

@ -580,6 +580,7 @@ namespace Pchp.CodeAnalysis.Symbols
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 @@ namespace Pchp.CodeAnalysis.Symbols
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

Просмотреть файл

@ -112,6 +112,11 @@ namespace Pchp.CodeAnalysis.Symbols
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;