Skip to content

Commit

Permalink
Temporary progress towards dotnet#1
Browse files Browse the repository at this point in the history
Temporary Progress Towards namespace features.
  • Loading branch information
checkedsums committed Jan 4, 2025
1 parent 50a8776 commit 3e56122
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 61 deletions.
4 changes: 2 additions & 2 deletions src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1697,6 +1697,7 @@ TypeDeclarationSyntax ParseClassOrStructOrInterfaceDeclaration(SyntaxList<Attrib
{
closeBrace = this.EatToken(SyntaxKind.CloseBraceToken);
}

/*
if (this.TryParseIdentifierToken() is SyntaxToken identifier)
{
Expand Down Expand Up @@ -2745,8 +2746,7 @@ private bool IsNoneOrIncompleteMember(SyntaxKind parentKind, SyntaxList<Attribut
{
result = incompleteMember;
}
else if (parentKind is SyntaxKind.NamespaceDeclaration or SyntaxKind.FileScopedNamespaceDeclaration ||
parentKind == SyntaxKind.CompilationUnit && !IsScript)
else if (parentKind == SyntaxKind.CompilationUnit && !IsScript)
{
result = this.AddErrorToLastToken(incompleteMember, ErrorCode.ERR_NamespaceUnexpected);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4796,8 +4796,6 @@ private void AddNonTypeMembers(
return;
}

bool reportMisplacedGlobalCode = !m.HasErrors;

switch (m.Kind())
{
case SyntaxKind.FieldDeclaration:
Expand All @@ -4807,12 +4805,6 @@ private void AddNonTypeMembers(
// Lang version check for ref-fields is done inside SourceMemberFieldSymbol;
_ = fieldSyntax.Declaration.Type.SkipScoped(out _).SkipRefInField(out var refKind);

if (IsImplicitClass && reportMisplacedGlobalCode)
{
diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected,
new SourceLocation(fieldSyntax.Declaration.Variables.First().Identifier));
}

var modifiers = SourceMemberFieldSymbol.MakeModifiers(this, fieldSyntax.Declaration.Variables[0].Identifier, fieldSyntax.Modifiers, isRefField: refKind != RefKind.None, diagnostics, out bool modifierErrors);
foreach (var variable in fieldSyntax.Declaration.Variables)
{
Expand Down Expand Up @@ -4847,11 +4839,6 @@ private void AddNonTypeMembers(
case SyntaxKind.MethodDeclaration:
{
var methodSyntax = (MethodDeclarationSyntax)m;
if (IsImplicitClass && reportMisplacedGlobalCode)
{
diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected,
new SourceLocation(methodSyntax.Identifier));
}

var method = SourceOrdinaryMethodSymbol.CreateMethodSymbol(this, bodyBinder, methodSyntax, diagnostics);
builder.NonTypeMembers.Add(method);
Expand All @@ -4861,11 +4848,6 @@ private void AddNonTypeMembers(
case SyntaxKind.ConstructorDeclaration:
{
var constructorSyntax = (ConstructorDeclarationSyntax)m;
if (IsImplicitClass && reportMisplacedGlobalCode)
{
diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected,
new SourceLocation(constructorSyntax.Identifier));
}

var constructor = SourceConstructorSymbol.CreateConstructorSymbol(this, constructorSyntax, diagnostics);
builder.NonTypeMembers.Add(constructor);
Expand All @@ -4875,11 +4857,6 @@ private void AddNonTypeMembers(
case SyntaxKind.DestructorDeclaration:
{
var destructorSyntax = (DestructorDeclarationSyntax)m;
if (IsImplicitClass && reportMisplacedGlobalCode)
{
diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected,
new SourceLocation(destructorSyntax.Identifier));
}

// CONSIDER: if this doesn't (directly or indirectly) override object.Finalize, the
// runtime won't consider it a finalizer and it will not be marked as a destructor
Expand All @@ -4893,12 +4870,6 @@ private void AddNonTypeMembers(
case SyntaxKind.PropertyDeclaration:
{
var propertySyntax = (PropertyDeclarationSyntax)m;
if (IsImplicitClass && reportMisplacedGlobalCode)
{
diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected,
new SourceLocation(propertySyntax.Identifier));
}

var property = SourcePropertySymbol.Create(this, bodyBinder, propertySyntax, diagnostics);
builder.NonTypeMembers.Add(property);

Expand Down Expand Up @@ -4943,12 +4914,6 @@ private void AddNonTypeMembers(
case SyntaxKind.EventFieldDeclaration:
{
var eventFieldSyntax = (EventFieldDeclarationSyntax)m;
if (IsImplicitClass && reportMisplacedGlobalCode)
{
diagnostics.Add(
ErrorCode.ERR_NamespaceUnexpected,
new SourceLocation(eventFieldSyntax.Declaration.Variables.First().Identifier));
}

foreach (VariableDeclaratorSyntax declarator in eventFieldSyntax.Declaration.Variables)
{
Expand Down Expand Up @@ -4995,11 +4960,6 @@ private void AddNonTypeMembers(
case SyntaxKind.EventDeclaration:
{
var eventSyntax = (EventDeclarationSyntax)m;
if (IsImplicitClass && reportMisplacedGlobalCode)
{
diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected,
new SourceLocation(eventSyntax.Identifier));
}

var @event = new SourceCustomEventSymbol(this, bodyBinder, eventSyntax, diagnostics);

Expand All @@ -5015,11 +4975,6 @@ private void AddNonTypeMembers(
case SyntaxKind.IndexerDeclaration:
{
var indexerSyntax = (IndexerDeclarationSyntax)m;
if (IsImplicitClass && reportMisplacedGlobalCode)
{
diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected,
new SourceLocation(indexerSyntax.ThisKeyword));
}

var indexer = SourcePropertySymbol.Create(this, bodyBinder, indexerSyntax, diagnostics);
builder.HaveIndexers = true;
Expand All @@ -5032,11 +4987,6 @@ private void AddNonTypeMembers(
case SyntaxKind.ConversionOperatorDeclaration:
{
var conversionOperatorSyntax = (ConversionOperatorDeclarationSyntax)m;
if (IsImplicitClass && reportMisplacedGlobalCode)
{
diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected,
new SourceLocation(conversionOperatorSyntax.OperatorKeyword));
}

var method = SourceUserDefinedConversionSymbol.CreateUserDefinedConversionSymbol(
this, bodyBinder, conversionOperatorSyntax, diagnostics);
Expand All @@ -5047,11 +4997,6 @@ private void AddNonTypeMembers(
case SyntaxKind.OperatorDeclaration:
{
var operatorSyntax = (OperatorDeclarationSyntax)m;
if (IsImplicitClass && reportMisplacedGlobalCode)
{
diagnostics.Add(ErrorCode.ERR_NamespaceUnexpected,
new SourceLocation(operatorSyntax.OperatorKeyword));
}

var method = SourceUserDefinedOperatorSymbol.CreateUserDefinedOperatorSymbol(
this, bodyBinder, operatorSyntax, diagnostics);
Expand Down Expand Up @@ -5108,10 +5053,6 @@ private void AddNonTypeMembers(

AddInitializer(ref instanceInitializers, null, globalStatement);
}
else if (reportMisplacedGlobalCode && !SyntaxFacts.IsSimpleProgramTopLevelStatement((GlobalStatementSyntax)m))
{
diagnostics.Add(ErrorCode.ERR_GlobalStatement, new SourceLocation(globalStatement));
}
}
break;

Expand Down

0 comments on commit 3e56122

Please sign in to comment.