diff --git a/IDEHelper/Compiler/BfDefBuilder.cpp b/IDEHelper/Compiler/BfDefBuilder.cpp index aa19e6e3..3e34d58d 100644 --- a/IDEHelper/Compiler/BfDefBuilder.cpp +++ b/IDEHelper/Compiler/BfDefBuilder.cpp @@ -1905,9 +1905,10 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) BfMethodDef* dynamicCastMethod = NULL; BfMethodDef* toStringMethod = NULL; bool needsEqualsMethod = ((mCurTypeDef->mTypeCode == BfTypeCode_Struct) || (mCurTypeDef->mTypeCode == BfTypeCode_Enum)) && (!mCurTypeDef->mIsStatic); + BfMethodDef* equalsOpMethod = NULL; BfMethodDef* equalsMethod = NULL; - BfMethodDef* strictEqualsMethod = NULL; - + BfMethodDef* strictEqualsMethod = NULL; + bool needsStaticInit = false; for (int methodIdx = 0; methodIdx < (int)mCurTypeDef->mMethods.size(); methodIdx++) { @@ -2025,6 +2026,10 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) { if (method->mName == BF_METHODNAME_MARKMEMBERS_STATIC) _SetMethod(staticMarkMethod, method); + if (method->mName == BF_METHODNAME_DEFAULT_EQUALS) + _SetMethod(equalsMethod, method); + if (method->mName == BF_METHODNAME_DEFAULT_STRICT_EQUALS) + _SetMethod(strictEqualsMethod, method); } else { @@ -2048,7 +2053,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) if ((method->mParams[0]->mTypeRef->ToString() == mCurTypeDef->mName->ToString()) && (method->mParams[1]->mTypeRef->ToString() == mCurTypeDef->mName->ToString())) { - _SetMethod(equalsMethod, method); + _SetMethod(equalsOpMethod, method); } } } @@ -2287,7 +2292,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) methodDef->mAddedAfterEmit = mIsComptime; } - if ((needsEqualsMethod) && (equalsMethod == NULL)) + if ((needsEqualsMethod) && (equalsMethod == NULL) && (equalsOpMethod == NULL)) { auto methodDef = new BfMethodDef(); mCurTypeDef->mMethods.push_back(methodDef); @@ -2301,7 +2306,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString) methodDef->mAddedAfterEmit = mIsComptime; } - if (needsEqualsMethod) + if ((needsEqualsMethod) && (strictEqualsMethod == NULL)) { auto methodDef = new BfMethodDef(); mCurTypeDef->mMethods.push_back(methodDef); diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index 351dbdd4..51f5194a 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -5245,7 +5245,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary& usedStrin typeFlags |= BfTypeFlags_Delegate; if (type->IsFunction()) typeFlags |= BfTypeFlags_Function; - if (type->WantsGCMarking()) + if ((type->mDefineState != BfTypeDefineState_CETypeInit) && (type->WantsGCMarking())) typeFlags |= BfTypeFlags_WantsMarking; int virtSlotIdx = -1; diff --git a/IDEHelper/Tests/src/Comptime.bf b/IDEHelper/Tests/src/Comptime.bf index 1d264f89..2fe333cd 100644 --- a/IDEHelper/Tests/src/Comptime.bf +++ b/IDEHelper/Tests/src/Comptime.bf @@ -80,6 +80,21 @@ namespace Tests } } + [IFaceA("C", InitVal=345)] + struct StructA + { + public int mA = 123; + + [OnCompile(.TypeInit), Comptime] + public static void Generate() + { + Compiler.EmitTypeBody(typeof(Self), """ + public int32 mB = 234; + public int32 GetValB() => mB; + """); + } + } + enum MethodAErr { ErrorA, @@ -168,6 +183,13 @@ namespace Tests Test.Assert(ca.mC == 345); Test.Assert(ca.GetValC() == 345); + StructA sa = .(); + Test.Assert(sa.mA == 123); + Test.Assert(sa.mB == 234); + Test.Assert(sa.GetValB() == 234); + Test.Assert(sa.mC == 345); + Test.Assert(sa.GetValC() == 345); + Compiler.Mixin("int val = 99;"); Test.Assert(val == 99);