Skip to content

Commit

Permalink
Warn on type named record
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Aug 24, 2020
1 parent 6ab11ee commit c83b766
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 13 deletions.
6 changes: 6 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -6416,6 +6416,12 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_CloneDisallowedInRecord" xml:space="preserve">
<value>Members named 'Clone' are disallowed in records.</value>
</data>
<data name="WRN_RecordNamedDisallowed" xml:space="preserve">
<value>A type should not be named 'record'.</value>
</data>
<data name="WRN_RecordNamedDisallowed_Title" xml:space="preserve">
<value>A type should not be named 'record'.</value>
</data>
<data name="ERR_NotOverridableAPIInRecord" xml:space="preserve">
<value>'{0}' must allow overriding because the containing record is not sealed.</value>
</data>
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 @@ -1853,7 +1853,7 @@ internal enum ErrorCode
ERR_InvalidWithReceiverType = 8857,
ERR_NoSingleCloneMethod = 8858,
ERR_CloneDisallowedInRecord = 8859,
// available = 8860,
WRN_RecordNamedDisallowed = 8860,
ERR_UnexpectedArgumentList = 8861,
ERR_UnexpectedOrMissingConstructorInitializerInRecord = 8862,
ERR_MultipleRecordParameterLists = 8863,
Expand Down
1 change: 1 addition & 0 deletions src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ internal static int GetWarningLevel(ErrorCode code)
case ErrorCode.WRN_IsPatternAlways:
case ErrorCode.WRN_SwitchExpressionNotExhaustiveWithWhen:
case ErrorCode.WRN_SwitchExpressionNotExhaustiveForNullWithWhen:
case ErrorCode.WRN_RecordNamedDisallowed:
return 1;
default:
return 0;
Expand Down

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
Expand Up @@ -285,7 +285,6 @@ private DeclarationModifiers MakeModifiers(TypeKind typeKind, DiagnosticBag diag
var mods = MakeAndCheckTypeModifiers(
defaultAccess,
allowedModifiers,
this,
diagnostics,
out modifierErrors);

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -411,13 +409,18 @@ 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 == "record")
{
diagnostics.Add(ErrorCode.WRN_RecordNamedDisallowed, declaration.Declarations[0].NameLocation, this.Name);
}

return result;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">Metoda označená jako [DoesNotReturn] by neměla vracet hodnotu</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">Eine mit [DoesNotReturn] gekennzeichnete Methode darf nicht zurückgegeben werden.</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">Un método marcado [DoesNotReturn] no debe devolver.</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">Une méthode marquée [DoesNotReturn] ne doit pas être retournée.</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">Un metodo contrassegnato con [DoesNotReturn] non deve essere restituito.</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">[DoesNotReturn] とマークされたメソッドを返すことはできません。</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">[DoesNotReturn]으로 표시된 메서드는 반환하지 않아야 합니다.</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">Metoda oznaczona [DoesNotReturn] nie powinna zwracać wartości.</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">Um método marcado como [DoesNotReturn] não deve ser retornado.</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">Метод, помеченный [DoesNotReturn], не должен возвращать значение.</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">[DoesNotReturn] olarak işaretlenen bir yöntem, döndürmemelidir.</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">不应返回标记为 [DoesNotReturn] 的方法。</target>
Expand Down
10 changes: 10 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,16 @@
<target state="new">Type does not implement the collection pattern; member is is not a public instance or extension method.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_RecordNamedDisallowed_Title">
<source>A type should not be named 'record'.</source>
<target state="new">A type should not be named 'record'.</target>
<note />
</trans-unit>
<trans-unit id="WRN_ShouldNotReturn">
<source>A method marked [DoesNotReturn] should not return.</source>
<target state="translated">標記 [DoesNotReturn] 的方法不應傳回。</target>
Expand Down
Loading

0 comments on commit c83b766

Please sign in to comment.