mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +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* dynamicCastMethod = NULL;
|
||||||
BfMethodDef* toStringMethod = NULL;
|
BfMethodDef* toStringMethod = NULL;
|
||||||
bool needsEqualsMethod = ((mCurTypeDef->mTypeCode == BfTypeCode_Struct) || (mCurTypeDef->mTypeCode == BfTypeCode_Enum)) && (!mCurTypeDef->mIsStatic);
|
bool needsEqualsMethod = ((mCurTypeDef->mTypeCode == BfTypeCode_Struct) || (mCurTypeDef->mTypeCode == BfTypeCode_Enum)) && (!mCurTypeDef->mIsStatic);
|
||||||
|
BfMethodDef* equalsOpMethod = NULL;
|
||||||
BfMethodDef* equalsMethod = NULL;
|
BfMethodDef* equalsMethod = NULL;
|
||||||
BfMethodDef* strictEqualsMethod = NULL;
|
BfMethodDef* strictEqualsMethod = NULL;
|
||||||
|
|
||||||
bool needsStaticInit = false;
|
bool needsStaticInit = false;
|
||||||
for (int methodIdx = 0; methodIdx < (int)mCurTypeDef->mMethods.size(); methodIdx++)
|
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)
|
if (method->mName == BF_METHODNAME_MARKMEMBERS_STATIC)
|
||||||
_SetMethod(staticMarkMethod, method);
|
_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
|
else
|
||||||
{
|
{
|
||||||
|
@ -2048,7 +2053,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
|
||||||
if ((method->mParams[0]->mTypeRef->ToString() == mCurTypeDef->mName->ToString()) &&
|
if ((method->mParams[0]->mTypeRef->ToString() == mCurTypeDef->mName->ToString()) &&
|
||||||
(method->mParams[1]->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;
|
methodDef->mAddedAfterEmit = mIsComptime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((needsEqualsMethod) && (equalsMethod == NULL))
|
if ((needsEqualsMethod) && (equalsMethod == NULL) && (equalsOpMethod == NULL))
|
||||||
{
|
{
|
||||||
auto methodDef = new BfMethodDef();
|
auto methodDef = new BfMethodDef();
|
||||||
mCurTypeDef->mMethods.push_back(methodDef);
|
mCurTypeDef->mMethods.push_back(methodDef);
|
||||||
|
@ -2301,7 +2306,7 @@ void BfDefBuilder::FinishTypeDef(bool wantsToString)
|
||||||
methodDef->mAddedAfterEmit = mIsComptime;
|
methodDef->mAddedAfterEmit = mIsComptime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needsEqualsMethod)
|
if ((needsEqualsMethod) && (strictEqualsMethod == NULL))
|
||||||
{
|
{
|
||||||
auto methodDef = new BfMethodDef();
|
auto methodDef = new BfMethodDef();
|
||||||
mCurTypeDef->mMethods.push_back(methodDef);
|
mCurTypeDef->mMethods.push_back(methodDef);
|
||||||
|
|
|
@ -5245,7 +5245,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
||||||
typeFlags |= BfTypeFlags_Delegate;
|
typeFlags |= BfTypeFlags_Delegate;
|
||||||
if (type->IsFunction())
|
if (type->IsFunction())
|
||||||
typeFlags |= BfTypeFlags_Function;
|
typeFlags |= BfTypeFlags_Function;
|
||||||
if (type->WantsGCMarking())
|
if ((type->mDefineState != BfTypeDefineState_CETypeInit) && (type->WantsGCMarking()))
|
||||||
typeFlags |= BfTypeFlags_WantsMarking;
|
typeFlags |= BfTypeFlags_WantsMarking;
|
||||||
|
|
||||||
int virtSlotIdx = -1;
|
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
|
enum MethodAErr
|
||||||
{
|
{
|
||||||
ErrorA,
|
ErrorA,
|
||||||
|
@ -168,6 +183,13 @@ namespace Tests
|
||||||
Test.Assert(ca.mC == 345);
|
Test.Assert(ca.mC == 345);
|
||||||
Test.Assert(ca.GetValC() == 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;");
|
Compiler.Mixin("int val = 99;");
|
||||||
Test.Assert(val == 99);
|
Test.Assert(val == 99);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue