Skip to content

Commit

Permalink
Merge pull request #45147 from 333fred/notnull-clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
333fred authored Jun 19, 2020
2 parents 8498815 + accbfd9 commit 92d1ce0
Show file tree
Hide file tree
Showing 21 changed files with 232 additions and 253 deletions.
14 changes: 10 additions & 4 deletions src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ internal ImmutableArray<TypeParameterConstraintClause> BindTypeParameterConstrai

if (i != 0)
{
diagnostics.Add(ErrorCode.ERR_RefValBoundMustBeFirst, syntax.GetFirstToken().GetLocation());
if (!reportedOverrideWithConstraints)
{
diagnostics.Add(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, syntax.GetFirstToken().GetLocation());
}

if (isForOverride && (constraints & (TypeParameterConstraintKind.ValueType | TypeParameterConstraintKind.ReferenceType)) != 0)
{
Expand Down Expand Up @@ -175,7 +178,10 @@ internal ImmutableArray<TypeParameterConstraintClause> BindTypeParameterConstrai

if (i != 0)
{
diagnostics.Add(ErrorCode.ERR_RefValBoundMustBeFirst, syntax.GetFirstToken().GetLocation());
if (!reportedOverrideWithConstraints)
{
diagnostics.Add(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, syntax.GetFirstToken().GetLocation());
}

if (isForOverride && (constraints & (TypeParameterConstraintKind.ValueType | TypeParameterConstraintKind.ReferenceType)) != 0)
{
Expand Down Expand Up @@ -233,7 +239,7 @@ internal ImmutableArray<TypeParameterConstraintClause> BindTypeParameterConstrai
case ConstraintContextualKeyword.Unmanaged:
if (i != 0)
{
diagnostics.Add(ErrorCode.ERR_UnmanagedConstraintMustBeFirst, typeSyntax.GetLocation());
diagnostics.Add(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, typeSyntax.GetLocation());
continue;
}

Expand All @@ -247,7 +253,7 @@ internal ImmutableArray<TypeParameterConstraintClause> BindTypeParameterConstrai
case ConstraintContextualKeyword.NotNull:
if (i != 0)
{
diagnostics.Add(ErrorCode.ERR_NotNullConstraintMustBeFirst, typeSyntax.GetLocation());
diagnostics.Add(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, typeSyntax.GetLocation());
}

constraints |= TypeParameterConstraintKind.NotNull;
Expand Down
10 changes: 2 additions & 8 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1359,8 +1359,8 @@
<data name="ERR_BadIncDecRetType" xml:space="preserve">
<value>The return type for ++ or -- operator must match the parameter type or be derived from the parameter type</value>
</data>
<data name="ERR_RefValBoundMustBeFirst" xml:space="preserve">
<value>The 'class' or 'struct' constraint must come before any other constraints</value>
<data name="ERR_TypeConstraintsMustBeUniqueAndFirst" xml:space="preserve">
<value>The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list.</value>
</data>
<data name="ERR_RefValBoundWithClass" xml:space="preserve">
<value>'{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint</value>
Expand Down Expand Up @@ -5704,9 +5704,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_NewBoundWithUnmanaged" xml:space="preserve">
<value>The 'new()' constraint cannot be used with the 'unmanaged' constraint</value>
</data>
<data name="ERR_UnmanagedConstraintMustBeFirst" xml:space="preserve">
<value>The 'unmanaged' constraint must come before any other constraints</value>
</data>
<data name="ERR_UnmanagedConstraintNotSatisfied" xml:space="preserve">
<value>The type '{2}' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter '{1}' in the generic type or method '{0}'</value>
</data>
Expand Down Expand Up @@ -6028,9 +6025,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="IDS_FeatureNestedStackalloc" xml:space="preserve">
<value>stackalloc in nested expressions</value>
</data>
<data name="ERR_NotNullConstraintMustBeFirst" xml:space="preserve">
<value>The 'notnull' constraint must come before any other constraints</value>
</data>
<data name="WRN_NullabilityMismatchInTypeParameterNotNullConstraint" xml:space="preserve">
<value>The type '{2}' cannot be used as type parameter '{1}' in the generic type or method '{0}'. Nullability of type argument '{2}' doesn't match 'notnull' constraint.</value>
</data>
Expand Down
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Portable/Errors/ErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ internal enum ErrorCode
ERR_AnonMethGrpInForEach = 446,
//ERR_AttrOnTypeArg = 447, unused in Roslyn. The scenario for which this error exists should, and does generate a parse error.
ERR_BadIncDecRetType = 448,
ERR_RefValBoundMustBeFirst = 449,
ERR_TypeConstraintsMustBeUniqueAndFirst = 449,
ERR_RefValBoundWithClass = 450,
ERR_NewBoundWithVal = 451,
ERR_RefConstraintNotSatisfied = 452,
Expand Down Expand Up @@ -1564,7 +1564,7 @@ internal enum ErrorCode
ERR_RefAssignNarrower = 8374,

ERR_NewBoundWithUnmanaged = 8375,
ERR_UnmanagedConstraintMustBeFirst = 8376,
//ERR_UnmanagedConstraintMustBeFirst = 8376,
ERR_UnmanagedConstraintNotSatisfied = 8377,
ERR_CantUseInOrOutInArglist = 8378,
ERR_ConWithUnmanagedCon = 8379,
Expand Down Expand Up @@ -1729,7 +1729,7 @@ internal enum ErrorCode

ERR_DefaultInterfaceImplementationInNoPIAType = 8711,
ERR_AbstractEventHasAccessors = 8712,
ERR_NotNullConstraintMustBeFirst = 8713,
//ERR_NotNullConstraintMustBeFirst = 8713,
WRN_NullabilityMismatchInTypeParameterNotNullConstraint = 8714,

ERR_DuplicateNullSuppression = 8715,
Expand Down
20 changes: 5 additions & 15 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,6 @@
<target state="new">The receiver type '{0}' is not a valid record type.</target>
<note />
</trans-unit>
<trans-unit id="ERR_NotNullConstraintMustBeFirst">
<source>The 'notnull' constraint must come before any other constraints</source>
<target state="translated">Omezení notnull musí být zadané před všemi ostatními omezeními.</target>
<note />
</trans-unit>
<trans-unit id="ERR_NullableDirectiveQualifierExpected">
<source>Expected 'enable', 'disable', or 'restore'</source>
<target state="translated">Očekávala se hodnota enable, disable nebo restore.</target>
Expand Down Expand Up @@ -737,6 +732,11 @@
<target state="translated">Typy řazené kolekce členů, které se používají jako operandy operátoru == nebo !=, musí mít odpovídající kardinality. U tohoto operátoru je ale kardinalita typů řazené kolekce členů vlevo {0} a vpravo {1}.</target>
<note />
</trans-unit>
<trans-unit id="ERR_TypeConstraintsMustBeUniqueAndFirst">
<source>The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list.</source>
<target state="new">The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list.</target>
<note />
</trans-unit>
<trans-unit id="ERR_TypelessNewIllegalTargetType">
<source>The type '{0}' may not be used as the target type of new()</source>
<target state="new">The type '{0}' may not be used as the target type of new()</target>
Expand Down Expand Up @@ -767,11 +767,6 @@
<target state="translated">{0}: Nejde zadat třídu omezení a zároveň omezení unmanaged.</target>
<note />
</trans-unit>
<trans-unit id="ERR_UnmanagedConstraintMustBeFirst">
<source>The 'unmanaged' constraint must come before any other constraints</source>
<target state="translated">Omezení unmanaged musí být zadané před všemi ostatními omezeními.</target>
<note />
</trans-unit>
<trans-unit id="ERR_UnmanagedConstraintNotSatisfied">
<source>The type '{2}' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter '{1}' in the generic type or method '{0}'</source>
<target state="translated">Typ {2} musí být typ, který nemůže mít hodnotu null, ani nesmí v žádné úrovni vnoření obsahovat pole, které by ji povolovalo, aby se dal použít jako parametr {1} v obecném typu nebo metodě {0}.</target>
Expand Down Expand Up @@ -4054,11 +4049,6 @@
<target state="translated">Typ vrácené hodnoty operátorů ++ a -- musí odpovídat danému typu parametru nebo z něho musí být odvozený.</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefValBoundMustBeFirst">
<source>The 'class' or 'struct' constraint must come before any other constraints</source>
<target state="translated">Omezení class nebo struct musí být zadané před všemi ostatními omezeními.</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefValBoundWithClass">
<source>'{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint</source>
<target state="translated">'{0}: Nejde zadat třídu omezení a zároveň omezení class nebo struct.</target>
Expand Down
20 changes: 5 additions & 15 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,6 @@
<target state="new">The receiver type '{0}' is not a valid record type.</target>
<note />
</trans-unit>
<trans-unit id="ERR_NotNullConstraintMustBeFirst">
<source>The 'notnull' constraint must come before any other constraints</source>
<target state="translated">Die notnull-Einschränkung muss vor allen anderen Einschränkungen stehen.</target>
<note />
</trans-unit>
<trans-unit id="ERR_NullableDirectiveQualifierExpected">
<source>Expected 'enable', 'disable', or 'restore'</source>
<target state="translated">"enable", "disable" oder "restore" erwartet.</target>
Expand Down Expand Up @@ -737,6 +732,11 @@
<target state="translated">Tupeltypen, die als Operanden eines ==- oder !=-Operators verwendet werden, müssen übereinstimmende Kardinalitäten aufweisen. Dieser Operator enthält jedoch Tupeltypen der Kardinalität "{0}" auf der linken und "{1}" auf der rechten Seite.</target>
<note />
</trans-unit>
<trans-unit id="ERR_TypeConstraintsMustBeUniqueAndFirst">
<source>The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list.</source>
<target state="new">The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list.</target>
<note />
</trans-unit>
<trans-unit id="ERR_TypelessNewIllegalTargetType">
<source>The type '{0}' may not be used as the target type of new()</source>
<target state="new">The type '{0}' may not be used as the target type of new()</target>
Expand Down Expand Up @@ -767,11 +767,6 @@
<target state="translated">"{0}": Eine Einschränkungsklasse kann nicht gleichzeitig mit einer unmanaged-Einschränkung angegeben werden.</target>
<note />
</trans-unit>
<trans-unit id="ERR_UnmanagedConstraintMustBeFirst">
<source>The 'unmanaged' constraint must come before any other constraints</source>
<target state="translated">Die unmanaged-Einschränkung muss vor allen anderen Einschränkungen stehen.</target>
<note />
</trans-unit>
<trans-unit id="ERR_UnmanagedConstraintNotSatisfied">
<source>The type '{2}' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter '{1}' in the generic type or method '{0}'</source>
<target state="translated">Der Typ "{2}" muss, ebenso wie sämtliche Felder auf jeder Schachtelungsebene, ein Non-Nullable-Typ sein, wenn er als {1}-Parameter im generischen Typ oder in der generischen Methode "{0}" verwendet werden soll.</target>
Expand Down Expand Up @@ -4054,11 +4049,6 @@
<target state="translated">Der Rückgabetyp für den Operator ++ oder -- muss der Parametertyp sein oder vom Parametertyp abgeleitet werden.</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefValBoundMustBeFirst">
<source>The 'class' or 'struct' constraint must come before any other constraints</source>
<target state="translated">Die class- oder struct-Einschränkung muss vor allen anderen Einschränkungen stehen.</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefValBoundWithClass">
<source>'{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint</source>
<target state="translated">'"{0}": Eine Einschränkungsklasse kann nicht gleichzeitig mit einer class- oder struct-Einschränkung angegeben werden.</target>
Expand Down
20 changes: 5 additions & 15 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,6 @@
<target state="new">The receiver type '{0}' is not a valid record type.</target>
<note />
</trans-unit>
<trans-unit id="ERR_NotNullConstraintMustBeFirst">
<source>The 'notnull' constraint must come before any other constraints</source>
<target state="translated">La restricción "notnull" debe preceder a cualquier otra restricción</target>
<note />
</trans-unit>
<trans-unit id="ERR_NullableDirectiveQualifierExpected">
<source>Expected 'enable', 'disable', or 'restore'</source>
<target state="translated">Se esperaba "enable", "disable" o "restore".</target>
Expand Down Expand Up @@ -737,6 +732,11 @@
<target state="translated">Los tipos de tupla utilizados como operandos de un operador == o != deben tener cardinalidades coincidentes. Pero este operador tiene tipos de tupla de cardinalidad {0} a la izquierda y {1} a la derecha.</target>
<note />
</trans-unit>
<trans-unit id="ERR_TypeConstraintsMustBeUniqueAndFirst">
<source>The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list.</source>
<target state="new">The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list.</target>
<note />
</trans-unit>
<trans-unit id="ERR_TypelessNewIllegalTargetType">
<source>The type '{0}' may not be used as the target type of new()</source>
<target state="new">The type '{0}' may not be used as the target type of new()</target>
Expand Down Expand Up @@ -767,11 +767,6 @@
<target state="translated">"{0}": no se puede especificar a la vez una clase de restricción y la restricción "unmanaged"</target>
<note />
</trans-unit>
<trans-unit id="ERR_UnmanagedConstraintMustBeFirst">
<source>The 'unmanaged' constraint must come before any other constraints</source>
<target state="translated">La restricción "unmanaged" debe preceder a cualquier otra restricción</target>
<note />
</trans-unit>
<trans-unit id="ERR_UnmanagedConstraintNotSatisfied">
<source>The type '{2}' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter '{1}' in the generic type or method '{0}'</source>
<target state="translated">"{2}" debe ser un tipo de valor que no acepta valores NULL, junto con todos los campos de cualquier nivel de anidamiento, para poder usarlo como parámetro "{1}" en el tipo o método genérico "{0}"</target>
Expand Down Expand Up @@ -4054,11 +4049,6 @@
<target state="translated">El tipo de valor devuelto para los operadores ++ o -- debe coincidir con el tipo de parámetro o derivarse de este</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefValBoundMustBeFirst">
<source>The 'class' or 'struct' constraint must come before any other constraints</source>
<target state="translated">Las restricciones 'class' o 'struct' deben preceder a cualquier otra restricción</target>
<note />
</trans-unit>
<trans-unit id="ERR_RefValBoundWithClass">
<source>'{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint</source>
<target state="translated">'{0}': no se puede especificar a la vez una clase de restricción y la restricción 'class' o 'struct'</target>
Expand Down
Loading

0 comments on commit 92d1ce0

Please sign in to comment.