From 7ca654aab190e89ae0684f775f673e31e1813de8 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Mon, 2 Dec 2024 12:06:45 -0500 Subject: [PATCH] Fixed crash attempting to bind function to const --- IDEHelper/Compiler/BfExprEvaluator.cpp | 3 ++- IDEHelper/Compiler/BfModuleTypeUtils.cpp | 2 +- IDEHelper/Tests/src/Functions.bf | 28 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 25c58c3e..fb2694a9 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -6805,7 +6805,8 @@ BfTypedValue BfExprEvaluator::CreateCall(BfAstNode* targetSrc, BfMethodInstance* { // We're attempting to directly invoke a non-virtual interface method, this will happen during the unspecialized pass // OR if we had an error and didn't find an implementing member in the actual target - if ((!mModule->mCurMethodInstance->mIsUnspecialized) && (!mModule->mCurTypeInstance->IsInterface())) + if (((mModule->mCurMethodInstance == NULL) || (!mModule->mCurMethodInstance->mIsUnspecialized)) && + (!mModule->mCurTypeInstance->IsInterface())) mModule->AssertErrorState(); if (returnType->IsInterface()) diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 7382e6b9..aac64fc0 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -13093,7 +13093,7 @@ BfIRValue BfModule::CastToFunction(BfAstNode* srcNode, const BfTypedValue& targe { if ((!methodInstance->mIsUnspecialized) && (HasCompiledOutput())) AssertErrorState(); - return GetDefaultValue(dataType); + return GetDefaultTypedValue(dataType, false, BfDefaultValueKind_Value).mValue; } bindFuncVal = methodRefMethod.mFunc; } diff --git a/IDEHelper/Tests/src/Functions.bf b/IDEHelper/Tests/src/Functions.bf index 24f22151..7dcaf804 100644 --- a/IDEHelper/Tests/src/Functions.bf +++ b/IDEHelper/Tests/src/Functions.bf @@ -159,6 +159,31 @@ namespace Tests } } + interface ITest + { + static void Func(); + } + + class ClassC where T : ITest + { + static function void() func = => T.Func; + + public static void Test() + { + func(); + } + } + + class Zoop : ITest + { + public static int sVal; + + public static void Func() + { + sVal = 123; + } + } + public static int UseFunc0(function int (T this, float f) func, T a, float b) { return func(a, b); @@ -226,6 +251,9 @@ namespace Tests }); StructCRepr.Test(); + + ClassC.Test(); + Test.Assert(Zoop.sVal == 123); } } }