1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 20:12:21 +02:00

Fixed tuple duplicate name check circular dependency issue

This commit is contained in:
Brian Fiete 2020-10-17 16:31:46 -07:00
parent 1a44732189
commit d46c60d956
3 changed files with 22 additions and 5 deletions

View file

@ -17203,6 +17203,7 @@ void BfExprEvaluator::Visit(BfTupleExpression* tupleExpr)
{ {
BfTypeVector fieldTypes; BfTypeVector fieldTypes;
Array<String> fieldNames; Array<String> fieldNames;
HashSet<String> fieldNameSet;
for (auto typedVal : typedValues) for (auto typedVal : typedValues)
{ {
auto type = typedVal.mType; auto type = typedVal.mType;
@ -17216,7 +17217,14 @@ void BfExprEvaluator::Visit(BfTupleExpression* tupleExpr)
if (requestedName == NULL) if (requestedName == NULL)
fieldNames.push_back(""); fieldNames.push_back("");
else else
fieldNames.push_back(requestedName->mNameNode->ToString()); {
auto fieldName = requestedName->mNameNode->ToString();
if (!fieldNameSet.TryAdd(fieldName, NULL))
{
mModule->Fail(StrFormat("A field named '%s' has already been declared", fieldName.c_str()), requestedName->mNameNode);
}
fieldNames.push_back(fieldName);
}
} }
tupleType = mModule->CreateTupleType(fieldTypes, fieldNames); tupleType = mModule->CreateTupleType(fieldTypes, fieldNames);
} }

View file

@ -2361,8 +2361,10 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
SetAndRestoreValue<BfTypeReference*> prevTypeRef(mContext->mCurTypeState->mCurBaseTypeRef, checkTypeRef); SetAndRestoreValue<BfTypeReference*> prevTypeRef(mContext->mCurTypeState->mCurBaseTypeRef, checkTypeRef);
SetAndRestoreValue<BfTypeDefineState> prevDefineState(typeInstance->mDefineState, BfTypeDefineState_ResolvingBaseType); SetAndRestoreValue<BfTypeDefineState> prevDefineState(typeInstance->mDefineState, BfTypeDefineState_ResolvingBaseType);
bool populateBase = !typeInstance->mTypeFailed; bool populateBase = !typeInstance->mTypeFailed;
auto checkType = ResolveTypeRef(checkTypeRef, populateBase ? BfPopulateType_Data : BfPopulateType_Declaration); auto checkType = ResolveTypeRef(checkTypeRef, BfPopulateType_Declaration);
if ((checkType != NULL) && (!checkType->IsInterface()) && (populateBase))
PopulateType(checkType, BfPopulateType_Data);
if (typeInstance->mDefineState >= BfTypeDefineState_Defined) if (typeInstance->mDefineState >= BfTypeDefineState_Defined)
{ {
@ -7206,8 +7208,9 @@ BfType* BfModule::ResolveTypeResult(BfTypeReference* typeRef, BfType* resolvedTy
if (typeInstance->IsTuple()) if (typeInstance->IsTuple())
{ {
if (typeInstance->mDefineState < BfTypeDefineState_Defined) //TODO: This can cause circular reference issues. Is there a case this is needed?
PopulateType(typeInstance); //if (typeInstance->mDefineState < BfTypeDefineState_Defined)
// PopulateType(typeInstance);
if (typeInstance->mHasDeclError) if (typeInstance->mHasDeclError)
{ {
if (auto tupleTypeRef = BfNodeDynCast<BfTupleTypeRef>(typeRef)) if (auto tupleTypeRef = BfNodeDynCast<BfTupleTypeRef>(typeRef))

View file

@ -1,6 +1,7 @@
#pragma warning disable 168 #pragma warning disable 168
using System; using System;
using System.Collections;
namespace Tests namespace Tests
{ {
@ -118,6 +119,11 @@ namespace Tests
int32 mB; int32 mB;
} }
struct StructK
{
Dictionary<int, StructK> dict;
}
[Test] [Test]
static void TestBasics() static void TestBasics()
{ {