diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs index 9a04811fc3044..363c5a6ad4fae 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs @@ -137,7 +137,10 @@ internal ImmutableArray 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) { @@ -175,7 +178,10 @@ internal ImmutableArray 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) { @@ -233,7 +239,7 @@ internal ImmutableArray BindTypeParameterConstrai case ConstraintContextualKeyword.Unmanaged: if (i != 0) { - diagnostics.Add(ErrorCode.ERR_UnmanagedConstraintMustBeFirst, typeSyntax.GetLocation()); + diagnostics.Add(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, typeSyntax.GetLocation()); continue; } @@ -247,7 +253,7 @@ internal ImmutableArray BindTypeParameterConstrai case ConstraintContextualKeyword.NotNull: if (i != 0) { - diagnostics.Add(ErrorCode.ERR_NotNullConstraintMustBeFirst, typeSyntax.GetLocation()); + diagnostics.Add(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, typeSyntax.GetLocation()); } constraints |= TypeParameterConstraintKind.NotNull; diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 3dc91256b2b83..181d536a74a1f 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -1359,8 +1359,8 @@ The return type for ++ or -- operator must match the parameter type or be derived from the parameter type - - The 'class' or 'struct' constraint must come before any other constraints + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint @@ -5695,9 +5695,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ The 'new()' constraint cannot be used with the 'unmanaged' constraint - - The 'unmanaged' constraint must come before any other constraints - 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}' @@ -6019,9 +6016,6 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ stackalloc in nested expressions - - The 'notnull' constraint must come before any other constraints - 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. diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 496fa9a5b0222..6e9c4a65d8da1 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -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, @@ -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, @@ -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, diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index cb8ae00e53d7a..4050a575341f8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - Omezení notnull musí být zadané před všemi ostatními omezeními. - - Expected 'enable', 'disable', or 'restore' Očekávala se hodnota enable, disable nebo restore. @@ -722,6 +717,11 @@ 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}. + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ {0}: Nejde zadat třídu omezení a zároveň omezení unmanaged. - - The 'unmanaged' constraint must come before any other constraints - Omezení unmanaged musí být zadané před všemi ostatními omezeními. - - 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}' 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}. @@ -4029,11 +4024,6 @@ Typ vrácené hodnoty operátorů ++ a -- musí odpovídat danému typu parametru nebo z něho musí být odvozený. - - The 'class' or 'struct' constraint must come before any other constraints - Omezení class nebo struct musí být zadané před všemi ostatními omezeními. - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '{0}: Nejde zadat třídu omezení a zároveň omezení class nebo struct. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 1eec6bb07f753..dfb17d10f5255 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - Die notnull-Einschränkung muss vor allen anderen Einschränkungen stehen. - - Expected 'enable', 'disable', or 'restore' "enable", "disable" oder "restore" erwartet. @@ -722,6 +717,11 @@ 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. + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ "{0}": Eine Einschränkungsklasse kann nicht gleichzeitig mit einer unmanaged-Einschränkung angegeben werden. - - The 'unmanaged' constraint must come before any other constraints - Die unmanaged-Einschränkung muss vor allen anderen Einschränkungen stehen. - - 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}' 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. @@ -4029,11 +4024,6 @@ Der Rückgabetyp für den Operator ++ oder -- muss der Parametertyp sein oder vom Parametertyp abgeleitet werden. - - The 'class' or 'struct' constraint must come before any other constraints - Die class- oder struct-Einschränkung muss vor allen anderen Einschränkungen stehen. - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '"{0}": Eine Einschränkungsklasse kann nicht gleichzeitig mit einer class- oder struct-Einschränkung angegeben werden. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 87013d35769f6..1b24fea19dca8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - La restricción "notnull" debe preceder a cualquier otra restricción - - Expected 'enable', 'disable', or 'restore' Se esperaba "enable", "disable" o "restore". @@ -722,6 +717,11 @@ 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. + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ "{0}": no se puede especificar a la vez una clase de restricción y la restricción "unmanaged" - - The 'unmanaged' constraint must come before any other constraints - La restricción "unmanaged" debe preceder a cualquier otra restricción - - 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}' "{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}" @@ -4029,11 +4024,6 @@ El tipo de valor devuelto para los operadores ++ o -- debe coincidir con el tipo de parámetro o derivarse de este - - The 'class' or 'struct' constraint must come before any other constraints - Las restricciones 'class' o 'struct' deben preceder a cualquier otra restricción - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '{0}': no se puede especificar a la vez una clase de restricción y la restricción 'class' o 'struct' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 267da2bf78f42..135871215fb18 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - La contrainte 'notnull' doit être placée avant toutes les autres contraintes - - Expected 'enable', 'disable', or 'restore' 'enable', 'disable' ou 'restore' attendu @@ -722,6 +717,11 @@ Les types de tuple utilisés en tant qu'opérandes d'un opérateur == ou != doivent avoir des cardinalités correspondantes. Toutefois, cet opérateur a des types de tuple de cardinalité {0} à gauche et {1} à droite. + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ '{0}' : impossible de spécifier à la fois une classe de contrainte et la contrainte 'unmanaged' - - The 'unmanaged' constraint must come before any other constraints - La contrainte 'unmanaged' doit être placée avant toutes les autres contraintes - - 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}' Le type '{2}' doit être un type valeur non-nullable, ainsi que l'ensemble des champs à tous les niveaux d'imbrication, pour pouvoir être utilisé en tant que paramètre '{1}' dans le type ou la méthode générique '{0}' @@ -4029,11 +4024,6 @@ Le type de retour pour l'opérateur ++ ou -- doit correspondre au type de paramètre ou en être dérivé - - The 'class' or 'struct' constraint must come before any other constraints - La contrainte 'class' ou 'struct' doit être placée avant toutes les autres contraintes - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '{0}' : impossible de spécifier à la fois une classe de contrainte et la contrainte 'class' ou 'struct' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 5c66bfbb6fad6..fa54f8ac8ad33 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - Il vincolo 'notnull' deve precedere gli altri vincoli - - Expected 'enable', 'disable', or 'restore' È previsto 'enable', 'disable' o 'restore' @@ -722,6 +717,11 @@ Le cardinalità dei tipi di tupla usati come operandi di un operatore == o != devono essere uguali, ma questo operatore presenta tipi di tupla con cardinalità {0} sulla sinistra e {1} sulla destra. + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ '{0}': non è possibile specificare sia una classe constraint che il vincolo 'unmanaged' - - The 'unmanaged' constraint must come before any other constraints - Il vincolo 'unmanaged' deve precedere gli altri vincoli - - 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}' Il tipo '{2}' deve essere un tipo valore che non ammette i valori Null, unitamente a tutti i campi a ogni livello di annidamento, per poter essere usato come parametro '{1}' nel tipo o metodo generico '{0}' @@ -4029,11 +4024,6 @@ Il tipo restituito per l'operatore ++ o -- deve essere uguale o derivare dal tipo che lo contiene. - - The 'class' or 'struct' constraint must come before any other constraints - Il vincolo 'class' o 'struct' deve precedere gli altri vincoli - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '{0}': non è possibile specificare sia una classe constraint che il vincolo 'class' o 'struct' diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 1ce4645e28c3f..06c2ffec95d0b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - 'notnull' 制約は、他の制約の前に指定されなければなりません - - Expected 'enable', 'disable', or 'restore' 'enable'、'disable'、'restore' のいずれかが必要でした @@ -722,6 +717,11 @@ 演算子 == または != のオペランドとして使用するタプルの型は、カーディナリティが一致している必要があります。しかし、この演算子は、左辺のタプルの型のカーディナリティが {0} で、右辺が {1} です。 + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ '{0}': 制約クラスと 'unmanaged' 制約の両方を指定することはできません - - The 'unmanaged' constraint must come before any other constraints - 'unmanaged' 制約は、他の制約の前に指定されなければなりません - - 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}' 型 '{2}' と、入れ子になっているあらゆるレベルのすべてのフィールドは、ジェネリック型またはメソッド '{0}' のパラメーター '{1}' として使用するために、Null 非許容の値型でなければなりません @@ -4029,11 +4024,6 @@ ++ または -- 演算子の戻り値の型は、パラメーター型と一致するか、パラメーター型から派生する必要があります。 - - The 'class' or 'struct' constraint must come before any other constraints - class' または 'struct' 制約は、他の制約の前に指定されなければなりません。 - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '{0}': 制約クラスと 'class' または 'struct' 制約の両方を指定することはできません。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index e1288e3b47b37..495da25bbde98 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - 'notnull' 제약 조건은 다른 모든 제약 조건보다 앞에 와야 합니다. - - Expected 'enable', 'disable', or 'restore' 'enable', 'disable' 또는 'restore'가 필요합니다. @@ -722,6 +717,11 @@ == 또는 != 연산자의 피연산자로 사용되는 튜플 형식에는 일치하는 카디널리티가 있어야 합니다. 하지만 이 연산자는 왼쪽에 {0}, 오른쪽에 {1} 카디널리티 형식의 튜플이 있습니다. + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ '{0}': constraint 클래스와 'unmanaged' 제약 조건을 둘 다 지정할 수는 없습니다. - - The 'unmanaged' constraint must come before any other constraints - 'unmanaged' 제약 조건은 다른 모든 제약 조건보다 앞에 와야 합니다. - - 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}' 제네릭 형식 또는 메서드 '{0}'에서 모든 중첩 수준의 모든 필드와 함께 '{2}' 형식을 '{1}' 매개 변수로 사용하려면 해당 형식이 null을 허용하지 않는 값 형식이어야 합니다. @@ -4029,11 +4024,6 @@ ++ 또는 -- 연산자의 반환 형식은 매개 변수 형식이거나 매개 변수 형식에서 파생되어야 합니다. - - The 'class' or 'struct' constraint must come before any other constraints - class' 또는 'struct' 제약 조건은 다른 모든 제약 조건보다 앞에 와야 합니다. - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '{0}': constraint 클래스와 'class' 또는 'struct' 제약 조건을 둘 다 지정할 수는 없습니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 3b4a2d428096b..376caf6c83b92 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - Ograniczenie „notnull” musi występować przed wszystkimi innymi ograniczeniami - - Expected 'enable', 'disable', or 'restore' Oczekiwano opcji „enable”, „disable” lub „restore” @@ -722,6 +717,11 @@ Typy krotek używane jako operandy operatorów == lub != muszą mieć zgodne kardynalności. Ten operator zawiera natomiast typy krotek o kardynalności {0} z lewej strony i {1} z prawej strony. + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ „{0}”: nie można jednocześnie określić klasy ograniczenia i ograniczenia „unmanaged” - - The 'unmanaged' constraint must come before any other constraints - Ograniczenie „unmanaged” musi występować przed wszystkimi innymi ograniczeniami - - 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}' Typ „{2}” musi być nienullowalnym typem wartości (podobnie jak wszystkie pola na wszystkich poziomach zagnieżdżenia), aby można było używać go jako parametru „{1}” w typie ogólnym lub metodzie ogólnej „{0}” @@ -4029,11 +4024,6 @@ Typ zwracany przez operator ++ lub -- musi odpowiadać typowi parametru lub pochodzić od typu parametru - - The 'class' or 'struct' constraint must come before any other constraints - Ograniczenie „class” lub „struct” musi występować przed wszystkimi innymi ograniczeniami - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '„{0}”: nie można jednocześnie określić klasy ograniczenia i ograniczenia „class” lub „struct” diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index c08aea3759945..b377ab9b8a23d 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - A restrição 'notnull' precisa vir antes de outras restrições - - Expected 'enable', 'disable', or 'restore' Esperava-se 'enable', 'disable' ou 'restore' @@ -722,6 +717,11 @@ Os tipos de tupla usados como operandos de um operador == ou != precisam ter cardinalidades correspondentes. No entanto, este operador tem tipos de tupla de cardinalidade {0} na esquerda e {1} na direita. + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ '{0}': não é possível especificar uma classe de restrição e a restrição 'unmanaged' - - The 'unmanaged' constraint must come before any other constraints - A restrição 'unmanaged' deve vir antes das outras restrições - - 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}' O tipo '{2}' deve ser um tipo de valor não anulável, juntamente com todos os campos em qualquer nível de aninhamento, para ser usado como um parâmetro '{1}' no tipo genérico ou no método '{0}' @@ -4027,11 +4022,6 @@ O tipo de retorno para o operador ++ ou -- deve corresponder ao tipo de parâmetro ou ser derivado do tipo de parâmetro - - The 'class' or 'struct' constraint must come before any other constraints - A restrição 'class' ou 'struct' deve vir antes de qualquer outra restrição - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '"{0}": não é possível especificar uma classe de restrição e a restrição "class" ou "struct" diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index b71df5fde3119..1f60a79af7a38 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - Ограничение "notnull" должно предшествовать любым другим ограничениям. - - Expected 'enable', 'disable', or 'restore' Ожидается "enable", "disable" или "restore" @@ -722,6 +717,11 @@ Типы кортежей, используемые в качестве операндов оператора == или !=, должны иметь соответствующие кратности. Однако этот оператор имеет типы кортежей с кратностью {0} слева и {1} справа. + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ "{0}": невозможно одновременно задать класс ограничения и ограничение "unmanaged" - - The 'unmanaged' constraint must come before any other constraints - Все другие ограничения должны следовать после ограничения "unmanaged" - - 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}' Чтобы тип "{2}" можно было использовать как параметр "{1}" в универсальном типе метода "{0}", он должен быть типом значения, который, как и все поля на любом уровне вложения, не допускает значения NULL. @@ -4029,11 +4024,6 @@ Возвращаемый тип оператора ++ или -- должен соответствовать типу параметра или быть производным от типа параметра. - - The 'class' or 'struct' constraint must come before any other constraints - Все другие ограничения должны следовать после ограничения "class" или "struct". - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '"{0}": невозможно одновременно задать класс ограничения и ограничения "class" или "struct". diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 71286ed2418ac..ce7fb96ede2c6 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - 'notnull' kısıtlaması diğer kısıtlamalardan önce gelmelidir - - Expected 'enable', 'disable', or 'restore' 'enable', 'disable' veya 'restore' bekleniyor @@ -722,6 +717,11 @@ == veya != işlecinin işleneni olarak kullanılan demet türlerinin kardinalitesi eşleşmelidir. Ancak bu işleç, solda {0} ve sağda {1} demet kardinalite türlerine sahip olmalıdır. + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ '{0}': hem bir kısıtlama sınıfı hem de 'unmanaged' kısıtlaması belirtilemez - - The 'unmanaged' constraint must come before any other constraints - 'unmanaged' kısıtlaması diğer kısıtlamalardan önce gelmelidir - - 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}' '{0}' genel türü veya yönteminde '{1}' parametresi olarak kullanılabilmesi için '{2}' türünün, herhangi bir iç içe geçme düzeyindeki tüm alanlarla birlikte null yapılamayan bir değer türü olması gerekir @@ -4029,11 +4024,6 @@ ++ veya -- işleci için dönüş türü parametre türüyle eşleşmeli ya da parametre türünden türemelidir - - The 'class' or 'struct' constraint must come before any other constraints - class' veya 'struct' kısıtlaması diğer kısıtlamalardan önce gelmelidir - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '{0}': hem bir kısıtlama sınıfı hem de 'class' veya 'struct' kısıtlaması belirtilemez diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index b9cdde0c4dc84..87d3299e67caa 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - "notnull" 约束必须在其他所有约束之前 - - Expected 'enable', 'disable', or 'restore' 应为 "enable"、"disable" 或 "restore" @@ -722,6 +717,11 @@ 用作 == 或 != 运算符的操作数的元组类型必须具有匹配的基数。但此运算符的基数的元组类型左侧为 {0},右侧为 {1}。 + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ “{0}”: 不能既指定约束类又指定 “unmanaged” 约束 - - The 'unmanaged' constraint must come before any other constraints - "unmanaged" 约束必须在其他任何约束之前 - - 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}' 类型“{2}”必须是不可为 null 值的类型,且包括任何嵌套级别的所有字段,才能用作泛型类型或方法“{0}”中的参数“{1}” @@ -4029,11 +4024,6 @@ ++ 或 -- 运算符的返回类型必须与参数类型匹配或从参数类型派生 - - The 'class' or 'struct' constraint must come before any other constraints - "class" 或 "struct" 约束必须在其他任何约束之前 - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '“{0}”: 不能既指定约束类又指定“class”或“struct”约束 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 0293eaf68bc9f..17f4495781ef2 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -512,11 +512,6 @@ The receiver type '{0}' is not a valid record type. - - The 'notnull' constraint must come before any other constraints - 'notnull' 限制式必須在所有其他限制式之前 - - Expected 'enable', 'disable', or 'restore' 應為 'enable'、'disable' 或 'restore' @@ -722,6 +717,11 @@ 作為 == 或 != 運算子之運算元使用的元組類型,必須具有相符的基數。但此運算子在左側的元組類型為基數 {0},在右側則為 {1}。 + + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + + The type '{0}' may not be used as the target type of new() The type '{0}' may not be used as the target type of new() @@ -752,11 +752,6 @@ '{0}': 不可在指定條件約束類型的同時,又指定 'unmanaged' 條件約束 - - The 'unmanaged' constraint must come before any other constraints - 'unmanaged' 條件約束必須在所有其他條件約束之前 - - 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}' 類型 '{2}' 及任何巢狀層級的所有欄位必須是不可為 null 的值類型,如此才能在泛型型別或方法 '{0}' 中將其用為參數 '{1}' @@ -4029,11 +4024,6 @@ ++ 或 -- 運算子的傳回類型,必須符合此參數類型或衍生自此參數類型。 - - The 'class' or 'struct' constraint must come before any other constraints - class' 或 'struct' 條件約束必須在所有其他條件約束之前 - - '{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint '{0}': 不可在指定條件約束類型的同時,又指定 'class' 或 'struct' 條件約束。 diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs index b07ed72eeb917..6c053d90f1761 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/SwitchTests.cs @@ -4715,7 +4715,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, diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/GenericConstraintsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/GenericConstraintsTests.cs index 43d1997792802..d2e972169eee9 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/GenericConstraintsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/GenericConstraintsTests.cs @@ -1827,9 +1827,9 @@ public void UnmanagedConstraint_Compilation_ReferenceType() var c = CreateCompilation("public class Test where T : class, unmanaged {}"); c.VerifyDiagnostics( - // (1,39): error CS8380: The 'unmanaged' constraint must come before any other constraints + // (1,39): error CS8869: The 'unmanaged' constraint cannot be combined with the 'class' constraint // public class Test where T : class, unmanaged {} - Diagnostic(ErrorCode.ERR_UnmanagedConstraintMustBeFirst, "unmanaged").WithLocation(1, 39)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "unmanaged").WithLocation(1, 39)); var typeParameter = c.GlobalNamespace.GetTypeMember("Test").TypeParameters.Single(); Assert.False(typeParameter.HasUnmanagedTypeConstraint); @@ -1845,9 +1845,9 @@ public void UnmanagedConstraint_Compilation_ValueType() var c = CreateCompilation("public class Test where T : struct, unmanaged {}"); c.VerifyDiagnostics( - // (1,40): error CS8380: The 'unmanaged' constraint must come before any other constraints + // (1,40): error CS8869: The 'unmanaged' constraint cannot be combined with the 'struct' constraint // public class Test where T : struct, unmanaged {} - Diagnostic(ErrorCode.ERR_UnmanagedConstraintMustBeFirst, "unmanaged").WithLocation(1, 40)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "unmanaged").WithLocation(1, 40)); var typeParameter = c.GlobalNamespace.GetTypeMember("Test").TypeParameters.Single(); Assert.False(typeParameter.HasUnmanagedTypeConstraint); @@ -1882,7 +1882,7 @@ public void UnmanagedConstraint_Compilation_AnotherClass_After() CreateCompilation("public class Test where T : System.Exception, unmanaged { }").VerifyDiagnostics( // (1,50): error CS8380: The 'unmanaged' constraint must come before any other constraints // public class Test where T : System.Exception, unmanaged { } - Diagnostic(ErrorCode.ERR_UnmanagedConstraintMustBeFirst, "unmanaged").WithLocation(1, 50)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "unmanaged").WithLocation(1, 50)); } [Fact] @@ -1891,7 +1891,7 @@ public void UnmanagedConstraint_Compilation_OtherValidTypes_After() CreateCompilation("public class Test where T : System.Enum, System.IDisposable, unmanaged { }").VerifyDiagnostics( // (1,65): error CS8376: The 'unmanaged' constraint must come before any other constraints // public class Test where T : System.Enum, System.IDisposable, unmanaged { } - Diagnostic(ErrorCode.ERR_UnmanagedConstraintMustBeFirst, "unmanaged").WithLocation(1, 65)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "unmanaged").WithLocation(1, 65)); } [Fact] @@ -1917,7 +1917,7 @@ public void UnmanagedConstraint_Compilation_AnotherParameter_After() CreateCompilation("public class Test where T : U, unmanaged { }").VerifyDiagnostics( // (1,38): error CS8380: The 'unmanaged' constraint must come before any other constraints // public class Test where T : U, unmanaged { } - Diagnostic(ErrorCode.ERR_UnmanagedConstraintMustBeFirst, "unmanaged").WithLocation(1, 38)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "unmanaged").WithLocation(1, 38)); } [Fact] @@ -4152,5 +4152,112 @@ public static unsafe void Main() Diagnostic(ErrorCode.ERR_FixedNotNeeded, "&ms.field").WithLocation(12, 27) ); } + + [Fact, WorkItem(45141, "https://github.com/dotnet/roslyn/issues/45141")] + public void CannotCombineDiagnostics() + { + var comp = CreateCompilation(@" +class C1 where T1 : class, struct, unmanaged, notnull +{ + void M1() where T2 : class, struct, unmanaged, notnull {} +} +class C2 where T1 : struct, class, unmanaged, notnull +{ + void M2() where T2 : struct, class, unmanaged, notnull {} +} +class C3 where T1 : class, class +{ + void M3() where T2 : class, class {} +} +"); + + comp.VerifyDiagnostics( + // (2,32): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // class C1 where T1 : class, struct, unmanaged, notnull + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "struct").WithLocation(2, 32), + // (2,40): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // class C1 where T1 : class, struct, unmanaged, notnull + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "unmanaged").WithLocation(2, 40), + // (2,51): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // class C1 where T1 : class, struct, unmanaged, notnull + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "notnull").WithLocation(2, 51), + // (4,37): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // void M1() where T2 : class, struct, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "struct").WithLocation(4, 37), + // (4,45): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // void M1() where T2 : class, struct, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "unmanaged").WithLocation(4, 45), + // (4,56): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // void M1() where T2 : class, struct, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "notnull").WithLocation(4, 56), + // (6,33): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // class C2 where T1 : struct, class, unmanaged, notnull + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(6, 33), + // (6,40): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // class C2 where T1 : struct, class, unmanaged, notnull + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "unmanaged").WithLocation(6, 40), + // (6,51): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // class C2 where T1 : struct, class, unmanaged, notnull + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "notnull").WithLocation(6, 51), + // (8,38): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // void M2() where T2 : struct, class, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(8, 38), + // (8,45): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // void M2() where T2 : struct, class, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "unmanaged").WithLocation(8, 45), + // (8,56): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // void M2() where T2 : struct, class, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "notnull").WithLocation(8, 56), + // (10,32): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // class C3 where T1 : class, class + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(10, 32), + // (12,37): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // void M3() where T2 : class, class {} + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(12, 37) + ); + } + + [Fact, WorkItem(45141, "https://github.com/dotnet/roslyn/issues/45141")] + public void CannotCombineDiagnostics_InheritedClassStruct() + { + var comp = CreateCompilation(@" +class C +{ + public virtual void M() where T1 : class {} +} +class D : C +{ + public override void M() where T1 : C, class, struct {} +} +class E +{ + public virtual void M() where T2 : struct {} +} +class F : E +{ + public override void M() where T2 : E, struct, class {} +} +class G +{ + public virtual void M() where T3 : unmanaged {} +} +class H : G +{ + public override void M() where T3 : G, unmanaged, struct {} +} +"); + + comp.VerifyDiagnostics( + // (8,45): error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly, except for either a 'class', or a 'struct' constraint. + // public override void M() where T1 : C, class, struct {} + Diagnostic(ErrorCode.ERR_OverrideWithConstraints, "C").WithLocation(8, 45), + // (16,45): error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly, except for either a 'class', or a 'struct' constraint. + // public override void M() where T2 : E, struct, class {} + Diagnostic(ErrorCode.ERR_OverrideWithConstraints, "E").WithLocation(16, 45), + // (24,45): error CS0460: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly, except for either a 'class', or a 'struct' constraint. + // public override void M() where T3 : G, unmanaged, struct {} + Diagnostic(ErrorCode.ERR_OverrideWithConstraints, "G").WithLocation(24, 45) + ); + } } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs index 1ee00a9b84b2b..8328ac79971c6 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs @@ -9020,11 +9020,11 @@ public override void Goo(T value) where T : struct, class { } "; var comp = CreateCompilation(source).VerifyDiagnostics( // (8,26): error CS0115: 'Derived.Goo(T)': no suitable method found to override - // public override void Goo(T value) where T : class, struct { } + // public override void Goo(T value) where T : struct, class { } Diagnostic(ErrorCode.ERR_OverrideNotExpected, "Goo").WithArguments("Derived.Goo(T)").WithLocation(8, 26), - // (8,60): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + // (8,60): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // public override void Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(8, 60)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(8, 60)); } [Fact] @@ -9044,9 +9044,9 @@ public override void Goo(T value) where T : class, struct { } // (8,26): error CS0115: 'Derived.Goo(T)': no suitable method found to override // public override void Goo(T value) where T : class, struct { } Diagnostic(ErrorCode.ERR_OverrideNotExpected, "Goo").WithArguments("Derived.Goo(T)").WithLocation(8, 26), - // (8,59): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + // (8,59): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // public override void Goo(T value) where T : class, struct { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "struct").WithLocation(8, 59)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "struct").WithLocation(8, 59)); } [Fact] @@ -9064,9 +9064,9 @@ public override void Goo(T value) where T : struct, class { } } "; var comp = CreateCompilation(source).VerifyDiagnostics( - // (9,60): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + // (9,60): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // public override void Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(9, 60)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(9, 60)); } [Fact] @@ -9086,10 +9086,9 @@ void I.Goo(T value) where T : struct, class { } // (8,12): error CS0539: 'C.Goo(T)' in explicit interface declaration is not found among members of the interface that can be implemented // void I.Goo(T value) where T : struct, class { } Diagnostic(ErrorCode.ERR_InterfaceMemberNotFound, "Goo").WithArguments("C.Goo(T)").WithLocation(8, 12), - // (8,46): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + // (8,46): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // void I.Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(8, 46) - ); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(8, 46)); } [Fact] @@ -9109,9 +9108,9 @@ void I.Goo(T value) where T : class, struct { } // (8,12): error CS0539: 'C.Goo(T)' in explicit interface declaration is not found among members of the interface that can be implemented // void I.Goo(T value) where T : class, struct { } Diagnostic(ErrorCode.ERR_InterfaceMemberNotFound, "Goo").WithArguments("C.Goo(T)").WithLocation(8, 12), - // (8,45): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + // (8,45): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // void I.Goo(T value) where T : class, struct { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "struct").WithLocation(8, 45)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "struct").WithLocation(8, 45)); } [Fact] @@ -9129,9 +9128,9 @@ void I.Goo(T value) where T : struct, class { } } "; var comp = CreateCompilation(source).VerifyDiagnostics( - // (9,46): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + // (9,46): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // void I.Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(9, 46)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(9, 46)); } [Fact] diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 8215db7fc46e5..8455d11226e6b 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -81658,12 +81658,12 @@ public static void F2(T2? t2) where T2 : notnull, struct }"; var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue()); comp.VerifyDiagnostics( - // (8,59): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + // (8,59): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // public static void F2(T2? t2) where T2 : notnull, struct - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "struct").WithLocation(8, 59), - // (4,58): error CS8713: The 'notnull' constraint must come before any other constraints + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "struct").WithLocation(8, 59), + // (4,58): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // public static void F1(T1? t1) where T1 : struct, notnull - Diagnostic(ErrorCode.ERR_NotNullConstraintMustBeFirst, "notnull").WithLocation(4, 58) + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "notnull").WithLocation(4, 58) ); var m = comp.SourceModule; @@ -81702,12 +81702,12 @@ public static void F2(T2? t2) where T2 : notnull, class }"; var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue()); comp.VerifyDiagnostics( - // (4,57): error CS8713: The 'notnull' constraint must come before any other constraints + // (4,57): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // public static void F1(T1? t1) where T1 : class, notnull - Diagnostic(ErrorCode.ERR_NotNullConstraintMustBeFirst, "notnull").WithLocation(4, 57), - // (8,59): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "notnull").WithLocation(4, 57), + // (8,59): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // public static void F2(T2? t2) where T2 : notnull, class - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(8, 59) + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(8, 59) ); var m = comp.SourceModule; @@ -81747,12 +81747,12 @@ public static void F2(T2? t2) where T2 : notnull, class? Assert.True(((MethodSymbol)comp.SourceModule.GlobalNamespace.GetMember("B.F1")).TypeParameters[0].IsNotNullable); comp.VerifyDiagnostics( - // (4,58): error CS8713: The 'notnull' constraint must come before any other constraints + // (4,58): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // public static void F1(T1? t1) where T1 : class?, notnull - Diagnostic(ErrorCode.ERR_NotNullConstraintMustBeFirst, "notnull").WithLocation(4, 58), - // (8,59): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "notnull").WithLocation(4, 58), + // (8,59): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // public static void F2(T2? t2) where T2 : notnull, class? - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(8, 59) + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(8, 59) ); var m = comp.SourceModule; @@ -82083,9 +82083,9 @@ public static void F1(T1? t1) where T1 : B, notnull }"; var comp = CreateCompilation(new[] { source }, options: WithNonNullTypesTrue()); comp.VerifyDiagnostics( - // (4,53): error CS8713: The 'notnull' constraint must come before any other constraints + // (4,53): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. // public static void F1(T1? t1) where T1 : B, notnull - Diagnostic(ErrorCode.ERR_NotNullConstraintMustBeFirst, "notnull").WithLocation(4, 53) + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "notnull").WithLocation(4, 53) ); var m = comp.SourceModule; diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs index 9894a5d168590..42ed9edd86061 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs @@ -868,7 +868,7 @@ public static void Main() } [Fact] - public void CS0449ERR_RefValBoundMustBeFirst() + public void CS0449ERR_TypeConstraintsMustBeUniqueAndFirst() { var test = @" interface I {} @@ -884,12 +884,15 @@ public void F6() where T : I {} } "; CreateCompilation(test).VerifyDiagnostics( - // (5,41): error CS0449: The 'class' or 'struct' constraint must come before any other constraints - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "struct").WithLocation(5, 41), - // (6,37): error CS0449: The 'class' or 'struct' constraint must come before any other constraints - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "struct").WithLocation(6, 37), - // (7,37): error CS0449: The 'class' or 'struct' constraint must come before any other constraints - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(7, 37)); + // (5,41): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // public void F1() where T : class, struct, I {} // CS0449 + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "struct").WithLocation(5, 41), + // (6,37): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // public void F2() where T : I, struct {} // CS0449 + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "struct").WithLocation(6, 37), + // (7,37): error CS0449: The 'class', 'struct', 'unmanaged', and 'notnull' constraints cannot be combined or duplicated, and must be specified first in the constraints list. + // public void F3() where T : I, class {} // CS0449 + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(7, 37)); } [Fact]