mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Throws error on duplicate tuple field name
This commit is contained in:
parent
640a20c961
commit
f1b685b4c7
3 changed files with 31 additions and 3 deletions
|
@ -1019,6 +1019,7 @@ void BfContext::RebuildType(BfType* type, bool deleteOnDemandTypes, bool rebuild
|
||||||
typeInst->mHasUnderlyingArray = false;
|
typeInst->mHasUnderlyingArray = false;
|
||||||
typeInst->mHasPackingHoles = false;
|
typeInst->mHasPackingHoles = false;
|
||||||
typeInst->mWantsGCMarking = false;
|
typeInst->mWantsGCMarking = false;
|
||||||
|
typeInst->mHasDeclError = false;
|
||||||
delete typeInst->mTypeInfoEx;
|
delete typeInst->mTypeInfoEx;
|
||||||
typeInst->mTypeInfoEx = NULL;
|
typeInst->mTypeInfoEx = NULL;
|
||||||
|
|
||||||
|
|
|
@ -703,7 +703,7 @@ void BfModule::CheckMemberNames(BfTypeInstance* typeInst)
|
||||||
if (!typeInst->IsTypeMemberIncluded(prop->mDeclaringType))
|
if (!typeInst->IsTypeMemberIncluded(prop->mDeclaringType))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
MemberRef memberRef;
|
MemberRef memberRef = { 0 };
|
||||||
memberRef.mMemberDef = prop;
|
memberRef.mMemberDef = prop;
|
||||||
memberRef.mTypeInst = checkType;
|
memberRef.mTypeInst = checkType;
|
||||||
memberRef.mProtection = prop->mProtection;
|
memberRef.mProtection = prop->mProtection;
|
||||||
|
@ -724,7 +724,7 @@ void BfModule::CheckMemberNames(BfTypeInstance* typeInst)
|
||||||
if (!typeInst->IsTypeMemberIncluded(field->mDeclaringType))
|
if (!typeInst->IsTypeMemberIncluded(field->mDeclaringType))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
MemberRef memberRef;
|
MemberRef memberRef = { 0 };
|
||||||
memberRef.mMemberDef = field;
|
memberRef.mMemberDef = field;
|
||||||
memberRef.mTypeInst = checkType;
|
memberRef.mTypeInst = checkType;
|
||||||
memberRef.mProtection = field->mProtection;
|
memberRef.mProtection = field->mProtection;
|
||||||
|
@ -805,6 +805,7 @@ void BfModule::CheckMemberNames(BfTypeInstance* typeInst)
|
||||||
if (secondMemberRef->mNameNode != NULL)
|
if (secondMemberRef->mNameNode != NULL)
|
||||||
error = Fail(StrFormat("A %s named '%s' has already been declared.", secondMemberRef->mKindName.c_str(), memberRef.mName.c_str()), secondMemberRef->mNameNode, true);
|
error = Fail(StrFormat("A %s named '%s' has already been declared.", secondMemberRef->mKindName.c_str(), memberRef.mName.c_str()), secondMemberRef->mNameNode, true);
|
||||||
showPrevious = true;
|
showPrevious = true;
|
||||||
|
typeInst->mHasDeclError = true;
|
||||||
}
|
}
|
||||||
if ((secondMemberRef->mNameNode != NULL) && (error != NULL))
|
if ((secondMemberRef->mNameNode != NULL) && (error != NULL))
|
||||||
mCompiler->mPassInstance->MoreInfo("Previous declaration", firstMemberRef->mNameNode);
|
mCompiler->mPassInstance->MoreInfo("Previous declaration", firstMemberRef->mNameNode);
|
||||||
|
@ -7156,6 +7157,30 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy
|
||||||
{
|
{
|
||||||
if ((typeInstance->mCustomAttributes != NULL) && (!typeRef->IsTemporary()))
|
if ((typeInstance->mCustomAttributes != NULL) && (!typeRef->IsTemporary()))
|
||||||
CheckErrorAttributes(typeInstance, NULL, typeInstance->mCustomAttributes, typeRef);
|
CheckErrorAttributes(typeInstance, NULL, typeInstance->mCustomAttributes, typeRef);
|
||||||
|
|
||||||
|
if (typeInstance->IsTuple())
|
||||||
|
{
|
||||||
|
if (typeInstance->mDefineState < BfTypeDefineState_Defined)
|
||||||
|
PopulateType(typeInstance);
|
||||||
|
if (typeInstance->mHasDeclError)
|
||||||
|
{
|
||||||
|
if (auto tupleTypeRef = BfNodeDynCast<BfTupleTypeRef>(typeRef))
|
||||||
|
{
|
||||||
|
HashSet<String> names;
|
||||||
|
for (auto nameIdentifier : tupleTypeRef->mFieldNames)
|
||||||
|
{
|
||||||
|
if (nameIdentifier == NULL)
|
||||||
|
continue;
|
||||||
|
StringT<64> fieldName;
|
||||||
|
nameIdentifier->ToString(fieldName);
|
||||||
|
if (!names.Add(fieldName))
|
||||||
|
{
|
||||||
|
Fail(StrFormat("A field named '%s' has already been declared", fieldName.c_str()), nameIdentifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolvedTypeRef;
|
return resolvedTypeRef;
|
||||||
|
|
|
@ -1797,6 +1797,7 @@ public:
|
||||||
bool mIsFinishingType;
|
bool mIsFinishingType;
|
||||||
bool mHasPackingHoles;
|
bool mHasPackingHoles;
|
||||||
bool mWantsGCMarking;
|
bool mWantsGCMarking;
|
||||||
|
bool mHasDeclError;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BfTypeInstance()
|
BfTypeInstance()
|
||||||
|
@ -1847,6 +1848,7 @@ public:
|
||||||
mIncludeAllMethods = false;
|
mIncludeAllMethods = false;
|
||||||
mWantsGCMarking = false;
|
mWantsGCMarking = false;
|
||||||
mHasParameterizedBase = false;
|
mHasParameterizedBase = false;
|
||||||
|
mHasDeclError = false;
|
||||||
mMergedFieldDataCount = 0;
|
mMergedFieldDataCount = 0;
|
||||||
mConstHolder = NULL;
|
mConstHolder = NULL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue