1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Fixed conv operator invocation of params value

This commit is contained in:
Brian Fiete 2022-02-02 08:35:25 -05:00
parent 438394099a
commit 1f5a56488b
2 changed files with 39 additions and 10 deletions

View file

@ -12659,6 +12659,11 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
SizedArray<BfResolvedArg, 1> args;
BfResolvedArg resolvedArg;
resolvedArg.mTypedValue = typedVal;
if (resolvedArg.mTypedValue.IsParams())
{
resolvedArg.mTypedValue = LoadOrAggregateValue(resolvedArg.mTypedValue);
resolvedArg.mTypedValue.mKind = BfTypedValueKind_Value;
}
args.push_back(resolvedArg);
BfMethodMatcher methodMatcher(srcNode, this, "", args, NULL);
methodMatcher.mCheckReturnType = toType;
@ -12891,7 +12896,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
if (doCall)
{
if (!silentFail)
//if (!silentFail)
methodMatcher.FlushAmbiguityError();
auto wantType = paramType;
@ -12921,7 +12926,18 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
if (doCall)
{
if ((castFlags & BfCastFlags_IsCastCheck) != 0)
{
// We've already verified that we can cast from the return type to toType in MethodMatcher.CheckMethod
return mBfIRBuilder->GetFakeVal();
}
result = exprEvaluator.CreateCall(&methodMatcher, BfTypedValue());
if (result.mType != toType)
return CastToValue(srcNode, result, toType, (BfCastFlags)(castFlags | BfCastFlags_Explicit | BfCastFlags_NoConversionOperator), resultFlags);
if (result)
{
if (resultFlags != NULL)
{
if (result.IsAddr())
@ -12932,14 +12948,11 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
else if (result.IsAddr())
result = LoadValue(result);
if (result.mType != toType)
return CastToValue(srcNode, result, toType, (BfCastFlags)(castFlags | BfCastFlags_Explicit | BfCastFlags_NoConversionOperator), resultFlags);
if (result)
return result.mValue;
}
}
}
}
// Default typed primitive 'underlying casts' happen after checking cast operators
if (explicitCast)

View file

@ -121,6 +121,19 @@ namespace Tests
{
}
public static int ParamsA(int a, params Span<int> ints)
{
int result = a;
for (var i in ints)
result += i;
return result;
}
public static int ParamsB(int a, params int[] ints)
{
return ParamsA(a, params ints);
}
[Test]
public static void TestBasics()
{
@ -149,6 +162,9 @@ namespace Tests
InCallObj("Hey");
Valueless valueless;
InCallValueless(valueless);
Test.Assert(ParamsA(100, 20, 3) == 123);
Test.Assert(ParamsB(100, 20, 3) == 123);
}
}
}