mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Fixed duplicate Equals methods with code generation on structs
This commit is contained in:
parent
02f17a889a
commit
18f9fb881f
3 changed files with 33 additions and 6 deletions
|
@ -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);
|
||||
|
|
|
@ -5245,7 +5245,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& 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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue