Skip to content

Commit

Permalink
Don't report modifier errors while parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed May 17, 2017
1 parent bab05cb commit d54126e
Show file tree
Hide file tree
Showing 28 changed files with 538 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ private static SingleNamespaceOrTypeDeclaration CreateImplicitClass(ICollection<
syntaxReference: container,
nameLocation: new SourceLocation(container),
memberNames: memberNames,
children: ImmutableArray<SingleTypeDeclaration>.Empty);
children: ImmutableArray<SingleTypeDeclaration>.Empty,
diagnostics: ImmutableArray<Diagnostic>.Empty);
}

/// <summary>
Expand Down Expand Up @@ -181,7 +182,8 @@ private SingleNamespaceOrTypeDeclaration CreateScriptClass(
syntaxReference: parentReference,
nameLocation: new SourceLocation(parentReference),
memberNames: memberNames,
children: children);
children: children,
diagnostics: ImmutableArray<Diagnostic>.Empty);

for (int i = fullName.Length - 2; i >= 0; i--)
{
Expand Down Expand Up @@ -279,24 +281,29 @@ private SingleNamespaceOrTypeDeclaration VisitTypeDeclaration(TypeDeclarationSyn
declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasBaseDeclarations;
}

if (node.ConstraintClauses.Count > 0)
var diagnostics = DiagnosticBag.GetInstance();
if (node.Arity == 0)
{
declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasConstraints;
Symbol.ReportErrorIfHasConstraints(node.ConstraintClauses, diagnostics);
}

var memberNames = GetNonTypeMemberNames(((Syntax.InternalSyntax.TypeDeclarationSyntax)(node.Green)).Members,
ref declFlags);

var modifiers = node.Modifiers.ToDeclarationModifiers(
allowPartial: true, diagnostics: diagnostics);

return new SingleTypeDeclaration(
kind: kind,
name: node.Identifier.ValueText,
modifiers: node.Modifiers.ToDeclarationModifiers(),
modifiers: modifiers,
arity: node.Arity,
declFlags: declFlags,
syntaxReference: _syntaxTree.GetReference(node),
nameLocation: new SourceLocation(node.Identifier),
memberNames: memberNames,
children: VisitTypeChildren(node));
children: VisitTypeChildren(node),
diagnostics: diagnostics.ToReadOnlyAndFree());
}

private ImmutableArray<SingleTypeDeclaration> VisitTypeChildren(TypeDeclarationSyntax node)
Expand Down Expand Up @@ -325,23 +332,27 @@ public override SingleNamespaceOrTypeDeclaration VisitDelegateDeclaration(Delega
? SingleTypeDeclaration.TypeDeclarationFlags.HasAnyAttributes
: SingleTypeDeclaration.TypeDeclarationFlags.None;

if (node.ConstraintClauses.Count > 0)
var diagnostics = DiagnosticBag.GetInstance();
if (node.Arity == 0)
{
declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasConstraints;
Symbol.ReportErrorIfHasConstraints(node.ConstraintClauses, diagnostics);
}

declFlags |= SingleTypeDeclaration.TypeDeclarationFlags.HasAnyNontypeMembers;

var modifiers = node.Modifiers.ToDeclarationModifiers(allowPartial: false, diagnostics: diagnostics);

return new SingleTypeDeclaration(
kind: DeclarationKind.Delegate,
name: node.Identifier.ValueText,
modifiers: node.Modifiers.ToDeclarationModifiers(),
modifiers: modifiers,
declFlags: declFlags,
arity: node.Arity,
syntaxReference: _syntaxTree.GetReference(node),
nameLocation: new SourceLocation(node.Identifier),
memberNames: SpecializedCollections.EmptyCollection<string>(),
children: ImmutableArray<SingleTypeDeclaration>.Empty);
children: ImmutableArray<SingleTypeDeclaration>.Empty,
diagnostics: diagnostics.ToReadOnlyAndFree());
}

public override SingleNamespaceOrTypeDeclaration VisitEnumDeclaration(EnumDeclarationSyntax node)
Expand All @@ -359,16 +370,20 @@ public override SingleNamespaceOrTypeDeclaration VisitEnumDeclaration(EnumDeclar

string[] memberNames = GetEnumMemberNames(members, ref declFlags);

var diagnostics = DiagnosticBag.GetInstance();
var modifiers = node.Modifiers.ToDeclarationModifiers(allowPartial: false, diagnostics: diagnostics);

return new SingleTypeDeclaration(
kind: DeclarationKind.Enum,
name: node.Identifier.ValueText,
arity: 0,
modifiers: node.Modifiers.ToDeclarationModifiers(),
modifiers: modifiers,
declFlags: declFlags,
syntaxReference: _syntaxTree.GetReference(node),
nameLocation: new SourceLocation(node.Identifier),
memberNames: memberNames,
children: ImmutableArray<SingleTypeDeclaration>.Empty);
children: ImmutableArray<SingleTypeDeclaration>.Empty,
diagnostics: diagnostics.ToReadOnlyAndFree());
}

private static string[] GetEnumMemberNames(SeparatedSyntaxList<EnumMemberDeclarationSyntax> members, ref SingleTypeDeclaration.TypeDeclarationFlags declFlags)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,6 @@ public bool AnyMemberHasAttributes
}
}

public bool HasConstraints
{
get
{
foreach (var decl in this.Declarations)
{
if (decl.HasConstraints)
{
return true;
}
}

return false;
}
}

public LexicalSortKey GetLexicalSortKey(CSharpCompilation compilation)
{
LexicalSortKey sortKey = new LexicalSortKey(Declarations[0].NameLocation, compilation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected SingleNamespaceDeclaration(
SyntaxReference syntaxReference,
SourceLocation nameLocation,
ImmutableArray<SingleNamespaceOrTypeDeclaration> children)
: base(name, syntaxReference, nameLocation)
: base(name, syntaxReference, nameLocation, diagnostics: ImmutableArray<Diagnostic>.Empty)
{
_children = children;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ internal abstract class SingleNamespaceOrTypeDeclaration : Declaration
private readonly SyntaxReference _syntaxReference;
private readonly SourceLocation _nameLocation;

/// <summary>
/// Any diagnostics reported while converting the Namespace/Type syntax into the Declaration
/// instance. Generally, we determine and store some diagnostics here because we don't want
/// to have to go back to Syntax when we have our NamespaceSymbol or NamedTypeSymbol.
/// </summary>
public readonly ImmutableArray<Diagnostic> Diagnostics;

protected SingleNamespaceOrTypeDeclaration(
string name,
SyntaxReference syntaxReference,
SourceLocation nameLocation)
SourceLocation nameLocation,
ImmutableArray<Diagnostic> diagnostics)
: base(name)
{
_syntaxReference = syntaxReference;
_nameLocation = nameLocation;
Diagnostics = diagnostics;
}

public SourceLocation Location
Expand Down Expand Up @@ -58,4 +67,4 @@ protected override ImmutableArray<Declaration> GetDeclarationChildren()

protected abstract ImmutableArray<SingleNamespaceOrTypeDeclaration> GetNamespaceOrTypeDeclarationChildren();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ internal enum TypeDeclarationFlags : byte
HasBaseDeclarations = 1 << 3,
AnyMemberHasAttributes = 1 << 4,
HasAnyNontypeMembers = 1 << 5,
HasConstraints = 1 << 6,
}

internal SingleTypeDeclaration(
Expand All @@ -38,10 +37,9 @@ internal SingleTypeDeclaration(
SyntaxReference syntaxReference,
SourceLocation nameLocation,
ICollection<string> memberNames,
ImmutableArray<SingleTypeDeclaration> children)
: base(name,
syntaxReference,
nameLocation)
ImmutableArray<SingleTypeDeclaration> children,
ImmutableArray<Diagnostic> diagnostics)
: base(name, syntaxReference, nameLocation, diagnostics)
{
Debug.Assert(kind != DeclarationKind.Namespace);

Expand Down Expand Up @@ -125,8 +123,6 @@ public bool AnyMemberHasAttributes
}
}

public bool HasConstraints => (_flags & TypeDeclarationFlags.HasConstraints) != 0;

public bool HasAnyNontypeMembers
{
get
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ internal enum ErrorCode
ERR_PartialMethodInvalidModifier = 750,
ERR_PartialMethodOnlyInPartialClass = 751,
ERR_PartialMethodCannotHaveOutParameters = 752,
ERR_PartialMethodOnlyMethods = 753,
// ERR_PartialMethodOnlyMethods = 753, Removed as it is subsumed by ERR_PartialMisplaced
ERR_PartialMethodNotExplicit = 754,
ERR_PartialMethodExtensionDifference = 755,
ERR_PartialMethodOnlyOneLatent = 756,
Expand Down
Loading

0 comments on commit d54126e

Please sign in to comment.