1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-04 23:36:00 +02:00

Added Variant support to reflected method invocation

This commit is contained in:
Brian Fiete 2020-06-22 17:06:26 -07:00
parent 5bdaeadc25
commit 2eb7ce3e1a
7 changed files with 387 additions and 7 deletions

View file

@ -1541,10 +1541,9 @@ bool BfMethodMatcher::CheckMethod(BfTypeInstance* targetTypeInstance, BfTypeInst
goto NoMatch;
}
if (paramsArrayType->IsArray())
{
auto arrayType = (BfArrayType*)paramsArrayType;
paramsElementType = arrayType->mGenericTypeInfo->mTypeGenericArguments[0];
if ((paramsArrayType->IsArray()) || (paramsArrayType->IsInstanceOf(mModule->mCompiler->mSpanTypeDef)))
{
paramsElementType = paramsArrayType->GetUnderlyingType();
while (argIdx < (int)mArguments.size())
{

View file

@ -8930,7 +8930,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
// * <-> Var
if ((typedVal.mType->IsVar()) || (toType->IsVar()))
{
return GetDefaultValue(toType);
return mBfIRBuilder->CreateUndefValue(mBfIRBuilder->MapType(toType));
}
// Generic param -> *

View file

@ -1226,6 +1226,12 @@ void DbgExprEvaluator::BeefTypeToString(const DbgTypedValue& val, String& outStr
_TypeCode mTypeCode;
uint8 mAlign;
};
struct _PointerType : _Type
{
_TypeCode mElementType;
};
struct _String
{
@ -1343,6 +1349,14 @@ void DbgExprEvaluator::BeefTypeToString(const DbgTypedValue& val, String& outStr
else
{
BfTypeCode typeCode = (BfTypeCode)mDebugger->ReadMemory<uint8>(typeAddr + (int)offsetof(_Type, mTypeCode));
if (typeCode == BfTypeCode_Pointer)
{
_TypeId elementType = mDebugger->ReadMemory<_TypeId>(typeAddr + offsetof(_PointerType, mElementType));
BeefTypeToString(GetBeefTypeById(elementType), outStr);
outStr += "*";
return;
}
switch (typeCode)
{
case BfTypeCode_None: outStr += "void"; break;

View file

@ -141,6 +141,10 @@ namespace Tests
Test.Assert(result.Get<float>() == 123);
result.Dispose();
result = methodInfo.Invoke(.(), .Create(100), .Create((int32)20), .Create(3.0f)).Get();
Test.Assert(result.Get<float>() == 123);
result.Dispose();
let attrC = methodInfo.GetCustomAttribute<AttrCAttribute>().Get();
Test.Assert(attrC.mA == 71);
Test.Assert(attrC.mB == 72);
@ -149,6 +153,10 @@ namespace Tests
var result = methodInfo.Invoke(ca, 100, (int32)20, 3.0f).Get();
Test.Assert(result.Get<float>() == 123);
result.Dispose();
result = methodInfo.Invoke(.Create(ca), .Create(100), .Create((int32)20), .Create(3.0f)).Get();
Test.Assert(result.Get<float>() == 123);
result.Dispose();
case 2:
Test.Assert(methodInfo.Name == "GetA");
var result = methodInfo.Invoke(ca, 123).Get();
@ -157,6 +165,9 @@ namespace Tests
result = methodInfo.Invoke(ca2, 123).Get();
Test.Assert(result.Get<int>() == 2123);
result.Dispose();
result = methodInfo.Invoke(.Create(ca2), .Create(123)).Get();
Test.Assert(result.Get<int>() == 2123);
result.Dispose();
case 3:
Test.Assert(methodInfo.Name == "__BfCtor");
Test.Assert(methodInfo.IsConstructor);