-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn on type named "record" #47094
Warn on type named "record" #47094
Changes from 4 commits
c83b766
ec43c41
4e0adf6
37c83d3
919f407
0694ca7
0ba1a06
7d1b65a
5e4496b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,7 +285,6 @@ private DeclarationModifiers MakeModifiers(TypeKind typeKind, DiagnosticBag diag | |
var mods = MakeAndCheckTypeModifiers( | ||
defaultAccess, | ||
allowedModifiers, | ||
this, | ||
diagnostics, | ||
out modifierErrors); | ||
|
||
|
@@ -324,7 +323,6 @@ private DeclarationModifiers MakeModifiers(TypeKind typeKind, DiagnosticBag diag | |
private DeclarationModifiers MakeAndCheckTypeModifiers( | ||
DeclarationModifiers defaultAccess, | ||
DeclarationModifiers allowedModifiers, | ||
SourceMemberContainerTypeSymbol self, | ||
DiagnosticBag diagnostics, | ||
out bool modifierErrors) | ||
{ | ||
|
@@ -356,7 +354,7 @@ private DeclarationModifiers MakeAndCheckTypeModifiers( | |
var info = ModifierUtils.CheckAccessibility(mods, this, isExplicitInterfaceImplementation: false); | ||
if (info != null) | ||
{ | ||
diagnostics.Add(info, self.Locations[0]); | ||
diagnostics.Add(info, this.Locations[0]); | ||
modifierErrors = true; | ||
} | ||
} | ||
|
@@ -383,12 +381,12 @@ private DeclarationModifiers MakeAndCheckTypeModifiers( | |
if ((result & DeclarationModifiers.Partial) == 0) | ||
{ | ||
// duplicate definitions | ||
switch (self.ContainingSymbol.Kind) | ||
switch (this.ContainingSymbol.Kind) | ||
{ | ||
case SymbolKind.Namespace: | ||
for (var i = 1; i < partCount; i++) | ||
{ | ||
diagnostics.Add(ErrorCode.ERR_DuplicateNameInNS, declaration.Declarations[i].NameLocation, self.Name, self.ContainingSymbol); | ||
diagnostics.Add(ErrorCode.ERR_DuplicateNameInNS, declaration.Declarations[i].NameLocation, this.Name, this.ContainingSymbol); | ||
modifierErrors = true; | ||
} | ||
break; | ||
|
@@ -397,7 +395,7 @@ private DeclarationModifiers MakeAndCheckTypeModifiers( | |
for (var i = 1; i < partCount; i++) | ||
{ | ||
if (ContainingType!.Locations.Length == 1 || ContainingType.IsPartial()) | ||
diagnostics.Add(ErrorCode.ERR_DuplicateNameInClass, declaration.Declarations[i].NameLocation, self.ContainingSymbol, self.Name); | ||
diagnostics.Add(ErrorCode.ERR_DuplicateNameInClass, declaration.Declarations[i].NameLocation, this.ContainingSymbol, this.Name); | ||
modifierErrors = true; | ||
} | ||
break; | ||
|
@@ -411,16 +409,32 @@ private DeclarationModifiers MakeAndCheckTypeModifiers( | |
var mods = singleDeclaration.Modifiers; | ||
if ((mods & DeclarationModifiers.Partial) == 0) | ||
{ | ||
diagnostics.Add(ErrorCode.ERR_MissingPartial, singleDeclaration.NameLocation, self.Name); | ||
diagnostics.Add(ErrorCode.ERR_MissingPartial, singleDeclaration.NameLocation, this.Name); | ||
modifierErrors = true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (this.Name == SyntaxFacts.GetText(SyntaxKind.RecordKeyword)) | ||
{ | ||
var location = declaration.Declarations[0].NameLocation; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this not issue an error if you had a partial declaration where the "first" declaration was escaped, but the second one wasn't? Consider testing something like: partial class @record {}
partial class record {}
``` #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I'm not even sure that this code is necessary? It seems that the only direct implementations of this type are In reply to: 477450215 [](ancestors = 477450215) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many tests fail without this logic. This is responsible for checking the name of the type. The logic added in For instance this test fails:
In reply to: 477453969 [](ancestors = 477453969,477450215) |
||
var nameText = location.SourceTree.GetRoot().FindToken(location.SourceSpan.Start).ToString(); | ||
ReportTypeNamedRecord(nameText, this.DeclaringCompilation, diagnostics, location); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
static internal void ReportTypeNamedRecord(string name, CSharpCompilation compilation, DiagnosticBag diagnostics, Location location) | ||
{ | ||
if (name == SyntaxFacts.GetText(SyntaxKind.RecordKeyword) && | ||
compilation.LanguageVersion >= MessageID.IDS_FeatureRecords.RequiredVersion()) | ||
{ | ||
diagnostics.Add(ErrorCode.WRN_RecordNamedDisallowed, location, name); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region Completion | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting a local. #Resolved