From 1f5a56488be3727fb5fa516141338f1a622cae99 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 2 Feb 2022 08:35:25 -0500 Subject: [PATCH] Fixed conv operator invocation of `params` value --- IDEHelper/Compiler/BfModuleTypeUtils.cpp | 33 +++++++++++++++++------- IDEHelper/Tests/src/MethodCalls.bf | 16 ++++++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 5c160bf7..aa29bd5f 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -12659,6 +12659,11 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp SizedArray 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,22 +12926,30 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp if (doCall) { - result = exprEvaluator.CreateCall(&methodMatcher, BfTypedValue()); - if (resultFlags != NULL) + if ((castFlags & BfCastFlags_IsCastCheck) != 0) { - if (result.IsAddr()) - *resultFlags = (BfCastResultFlags)(*resultFlags | BfCastResultFlags_IsAddr); - if (result.mKind == BfTypedValueKind_TempAddr) - *resultFlags = (BfCastResultFlags)(*resultFlags | BfCastResultFlags_IsTemp); + // We've already verified that we can cast from the return type to toType in MethodMatcher.CheckMethod + return mBfIRBuilder->GetFakeVal(); } - else if (result.IsAddr()) - result = LoadValue(result); - + + 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()) + *resultFlags = (BfCastResultFlags)(*resultFlags | BfCastResultFlags_IsAddr); + if (result.mKind == BfTypedValueKind_TempAddr) + *resultFlags = (BfCastResultFlags)(*resultFlags | BfCastResultFlags_IsTemp); + } + else if (result.IsAddr()) + result = LoadValue(result); + return result.mValue; + } } } } diff --git a/IDEHelper/Tests/src/MethodCalls.bf b/IDEHelper/Tests/src/MethodCalls.bf index 8ccefe7d..48a17492 100644 --- a/IDEHelper/Tests/src/MethodCalls.bf +++ b/IDEHelper/Tests/src/MethodCalls.bf @@ -121,6 +121,19 @@ namespace Tests { } + public static int ParamsA(int a, params Span 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); } } }