mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Improved semicolon handling for inline anonymous type references
This commit is contained in:
parent
34cfe603e6
commit
a6a891d800
3 changed files with 36 additions and 8 deletions
|
@ -15588,11 +15588,12 @@ void BfExprEvaluator::CheckObjectCreateTypeRef(BfType* expectingType, BfAstNode*
|
|||
auto arrayType = (BfArrayType*)expectingType;
|
||||
expectingType = arrayType->mGenericTypeInfo->mTypeGenericArguments[0];
|
||||
}
|
||||
|
||||
|
||||
auto expectingTypeInst = expectingType->ToTypeInstance();
|
||||
if (expectingTypeInst != NULL)
|
||||
{
|
||||
autoComplete->AddTypeInstanceEntry(expectingTypeInst);
|
||||
if (!expectingTypeInst->IsAnonymous())
|
||||
autoComplete->AddTypeInstanceEntry(expectingTypeInst);
|
||||
}
|
||||
else
|
||||
autoComplete->mDefaultSelection = mModule->TypeToString(expectingType);
|
||||
|
|
|
@ -8230,13 +8230,24 @@ BfScopedInvocationTarget* BfReducer::CreateScopedInvocationTarget(BfAstNode*& ta
|
|||
void BfReducer::InitAnonymousType(BfTypeDeclaration* typeDecl)
|
||||
{
|
||||
auto block = BfNodeDynCast<BfBlock>(typeDecl->mDefineNode);
|
||||
int blockId = 0;
|
||||
if (blockId != NULL)
|
||||
{
|
||||
blockId = block->mParserBlockId;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto parser = mSource->ToParser();
|
||||
if (parser != NULL)
|
||||
blockId = parser->mCurBlockId + typeDecl->mSrcStart;
|
||||
}
|
||||
|
||||
String name;
|
||||
auto parserData = typeDecl->GetParserData();
|
||||
name = "_Anon_";
|
||||
|
||||
auto parseFileData = parserData->mParseFileData;
|
||||
int uniqueId = parseFileData->GetUniqueId(block->mParserBlockId);
|
||||
int uniqueId = parseFileData->GetUniqueId(blockId);
|
||||
name += StrFormat("%d", uniqueId);
|
||||
|
||||
int len = (int)name.length() + 1;
|
||||
|
@ -9464,12 +9475,20 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
|
|||
|
||||
if (baseTypeIdx > 0)
|
||||
{
|
||||
bool hasComma = false;
|
||||
|
||||
if (auto tokenNode = BfNodeDynCast<BfTokenNode>(nextNode))
|
||||
{
|
||||
if (tokenNode->mToken == BfToken_Semicolon)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if ((tokenNode->mToken == BfToken_Semicolon) && (!isAnonymous))
|
||||
break;
|
||||
if (tokenNode->mToken == BfToken_Comma)
|
||||
hasComma = true;
|
||||
}
|
||||
|
||||
if ((!hasComma) && (isAnonymous))
|
||||
{
|
||||
// End type declaration
|
||||
break;
|
||||
}
|
||||
|
||||
BfTokenNode* commaToken = NULL;
|
||||
|
@ -9551,7 +9570,7 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
|
|||
|
||||
if (tokenNode != NULL)
|
||||
{
|
||||
if (tokenNode->GetToken() == BfToken_Semicolon)
|
||||
if ((tokenNode->GetToken() == BfToken_Semicolon) && (!isAnonymous))
|
||||
{
|
||||
typeDeclaration->mDefineNode = tokenNode;
|
||||
MoveNode(tokenNode, typeDeclaration);
|
||||
|
@ -9560,6 +9579,9 @@ BfAstNode* BfReducer::CreateTopLevelObject(BfTokenNode* tokenNode, BfAttributeDi
|
|||
}
|
||||
}
|
||||
|
||||
if ((isAnonymous) && (!BfNodeIsA<BfBlock>(nextNode)))
|
||||
return typeDeclaration;
|
||||
|
||||
auto blockNode = ExpectBlockAfter(typeDeclaration);
|
||||
if (blockNode != NULL)
|
||||
{
|
||||
|
|
|
@ -45,6 +45,8 @@ class Anonymous
|
|||
public int Val = 123;
|
||||
}
|
||||
|
||||
public static class : this(int x, int y) sValA = new .(3, 4) ~ delete _;
|
||||
|
||||
[Test]
|
||||
public static void TestBasics()
|
||||
{
|
||||
|
@ -85,5 +87,8 @@ class Anonymous
|
|||
|
||||
var str = ca.ToString(.. scope .());
|
||||
Test.Assert(str == "ClassA override");
|
||||
|
||||
Test.Assert(sValA.x == 3);
|
||||
Test.Assert(sValA.y == 4);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue