From 7ca0c7eb991aec6d2434f2b118f0df533922f20d Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Sat, 13 Jun 2020 12:32:46 -0700 Subject: [PATCH 1/4] Report better errors when multiple invalid constraints are combined Instead of reporting that a constraint must come first, if there are multiple constraints that must come first, we now report that these constraints cannot be combined. We also suppress these errors if a previous error about inherited constraints was reported. Fixes https://github.com/dotnet/roslyn/issues/45141. --- .../Portable/Binder/Binder_Constraints.cs | 32 +++- .../CSharp/Portable/CSharpResources.resx | 15 ++ .../CSharp/Portable/Errors/ErrorCode.cs | 1 + .../CSharp/Portable/Errors/MessageID.cs | 4 + .../Portable/xlf/CSharpResources.cs.xlf | 25 +++ .../Portable/xlf/CSharpResources.de.xlf | 25 +++ .../Portable/xlf/CSharpResources.es.xlf | 25 +++ .../Portable/xlf/CSharpResources.fr.xlf | 25 +++ .../Portable/xlf/CSharpResources.it.xlf | 25 +++ .../Portable/xlf/CSharpResources.ja.xlf | 25 +++ .../Portable/xlf/CSharpResources.ko.xlf | 25 +++ .../Portable/xlf/CSharpResources.pl.xlf | 25 +++ .../Portable/xlf/CSharpResources.pt-BR.xlf | 25 +++ .../Portable/xlf/CSharpResources.ru.xlf | 25 +++ .../Portable/xlf/CSharpResources.tr.xlf | 25 +++ .../Portable/xlf/CSharpResources.zh-Hans.xlf | 25 +++ .../Portable/xlf/CSharpResources.zh-Hant.xlf | 25 +++ .../Semantics/GenericConstraintsTests.cs | 149 +++++++++++++++++- .../Semantics/InheritanceBindingTests.cs | 26 +-- .../Semantics/NullableReferenceTypesTests.cs | 24 +-- 20 files changed, 543 insertions(+), 33 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs index 9a04811fc3044..df6006e9784c5 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs @@ -126,6 +126,7 @@ internal ImmutableArray BindTypeParameterConstrai Debug.Assert(!InExecutableBinder); // Cannot eagerly report diagnostics handled by LazyMissingNonNullTypesContextDiagnosticInfo bool hasTypeLikeConstraint = false; bool reportedOverrideWithConstraints = false; + MessageID? firstTypeConstraintString = null; for (int i = 0, n = constraintsSyntax.Count; i < n; i++) { @@ -137,7 +138,10 @@ internal ImmutableArray BindTypeParameterConstrai if (i != 0) { - diagnostics.Add(ErrorCode.ERR_RefValBoundMustBeFirst, syntax.GetFirstToken().GetLocation()); + if (!reportedOverrideWithConstraints) + { + reportNotFirstOrCannotCombine(diagnostics, syntax.GetFirstToken().GetLocation(), ErrorCode.ERR_RefValBoundMustBeFirst, MessageID.IDS_Class, firstTypeConstraintString); + } if (isForOverride && (constraints & (TypeParameterConstraintKind.ValueType | TypeParameterConstraintKind.ReferenceType)) != 0) { @@ -145,6 +149,7 @@ internal ImmutableArray BindTypeParameterConstrai } } + firstTypeConstraintString ??= MessageID.IDS_Class; var constraintSyntax = (ClassOrStructConstraintSyntax)syntax; SyntaxToken questionToken = constraintSyntax.QuestionToken; if (questionToken.IsKind(SyntaxKind.QuestionToken)) @@ -175,7 +180,10 @@ internal ImmutableArray BindTypeParameterConstrai if (i != 0) { - diagnostics.Add(ErrorCode.ERR_RefValBoundMustBeFirst, syntax.GetFirstToken().GetLocation()); + if (!reportedOverrideWithConstraints) + { + reportNotFirstOrCannotCombine(diagnostics, syntax.GetFirstToken().GetLocation(), ErrorCode.ERR_RefValBoundMustBeFirst, MessageID.IDS_Struct, firstTypeConstraintString); + } if (isForOverride && (constraints & (TypeParameterConstraintKind.ValueType | TypeParameterConstraintKind.ReferenceType)) != 0) { @@ -183,6 +191,7 @@ internal ImmutableArray BindTypeParameterConstrai } } + firstTypeConstraintString ??= MessageID.IDS_Struct; constraints |= TypeParameterConstraintKind.ValueType; continue; case SyntaxKind.ConstructorConstraint: @@ -233,10 +242,12 @@ internal ImmutableArray BindTypeParameterConstrai case ConstraintContextualKeyword.Unmanaged: if (i != 0) { - diagnostics.Add(ErrorCode.ERR_UnmanagedConstraintMustBeFirst, typeSyntax.GetLocation()); + reportNotFirstOrCannotCombine(diagnostics, typeSyntax.GetLocation(), ErrorCode.ERR_UnmanagedConstraintMustBeFirst, MessageID.IDS_Unmanaged, firstTypeConstraintString); continue; } + firstTypeConstraintString ??= MessageID.IDS_Unmanaged; + // This should produce diagnostics if the types are missing GetWellKnownType(WellKnownType.System_Runtime_InteropServices_UnmanagedType, diagnostics, typeSyntax); GetSpecialType(SpecialType.System_ValueType, diagnostics, typeSyntax); @@ -247,9 +258,10 @@ internal ImmutableArray BindTypeParameterConstrai case ConstraintContextualKeyword.NotNull: if (i != 0) { - diagnostics.Add(ErrorCode.ERR_NotNullConstraintMustBeFirst, typeSyntax.GetLocation()); + reportNotFirstOrCannotCombine(diagnostics, typeSyntax.GetLocation(), ErrorCode.ERR_NotNullConstraintMustBeFirst, MessageID.IDS_Notnull, firstTypeConstraintString); } + firstTypeConstraintString ??= MessageID.IDS_Notnull; constraints |= TypeParameterConstraintKind.NotNull; continue; @@ -286,6 +298,18 @@ static void reportOverrideWithConstraints(ref bool reportedOverrideWithConstrain reportedOverrideWithConstraints = true; } } + + static void reportNotFirstOrCannotCombine(DiagnosticBag diagnostics, Location constraintLocation, ErrorCode notFirstDiagnostic, MessageID currentConstraintString, MessageID? firstConstraintString) + { + if (firstConstraintString is MessageID firstConstraint) + { + diagnostics.Add(ErrorCode.ERR_CannotCombineTypeConstraints, constraintLocation, currentConstraintString.Localize(), firstConstraint.Localize()); + } + else + { + diagnostics.Add(notFirstDiagnostic, constraintLocation); + } + } } internal ImmutableArray GetDefaultTypeParameterConstraintClauses(TypeParameterListSyntax typeParameterList) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 3dc91256b2b83..b7c56ca1a37d0 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -6262,4 +6262,19 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ A copy constructor in a record must call a copy constructor of the base, or a parameterless object constructor if the record inherits from object. + + class + + + struct + + + unmanaged + + + notnull + + + The '{0}' constraint cannot be combined with the '{1}' constraint + diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 496fa9a5b0222..4f9d29e732d6f 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -1835,6 +1835,7 @@ internal enum ErrorCode ERR_BadRecordMemberForPositionalParameter = 8866, ERR_NoCopyConstructorInBaseType = 8867, ERR_CopyConstructorMustInvokeBaseCopyConstructor = 8868, + ERR_CannotCombineTypeConstraints = 8869, #endregion diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs index fd3b09596ef28..569060b6d242b 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs @@ -206,6 +206,10 @@ internal enum MessageID IDS_FeatureInitOnlySetters = MessageBase + 12781, IDS_FeatureRecords = MessageBase + 12782, IDS_FeatureNullPointerConstantPattern = MessageBase + 12783, + IDS_Class = MessageBase + 12784, + IDS_Struct = MessageBase + 12785, + IDS_Unmanaged = MessageBase + 12786, + IDS_Notnull = MessageBase + 12787, } // Message IDs may refer to strings that need to be localized. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index cb8ae00e53d7a..0134a34ad2bd1 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -152,6 +152,11 @@ Chyba syntaxe příkazového řádku: {0} není platná hodnota možnosti {1}. Hodnota musí mít tvar {2}. + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation implementace výchozího rozhraní @@ -1364,11 +1374,21 @@ <null> + + notnull + notnull + + constraints for override and explicit interface implementation methods omezení pro metody přepsání a explicitní implementace rozhraní + + struct + struct + + <throw expression> <výraz throw> @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 1eec6bb07f753..008a4101e9d83 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -152,6 +152,11 @@ Fehler in der Befehlszeilensyntax: "{0}" ist kein gültiger Wert für die Option "{1}". Der Wert muss im Format "{2}" vorliegen. + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation Standardschnittstellenimplementierung @@ -1364,11 +1374,21 @@ <NULL> + + notnull + notnull + + constraints for override and explicit interface implementation methods Einschränkungen für Außerkraftsetzung und explizite Schnittstellenimplementierungsmethoden + + struct + struct + + <throw expression> throw-Ausdruck @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 87013d35769f6..6b96c7f8348ac 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -152,6 +152,11 @@ Error de sintaxis de la línea de comandos: "{0}" no es un valor válido para la opción "{1}". El valor debe tener el formato "{2}". + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation implementación de interfaz predeterminada @@ -1364,11 +1374,21 @@ <NULL> + + notnull + notnull + + constraints for override and explicit interface implementation methods restricciones para métodos de implementación de interfaz explícita e invalidación + + struct + struct + + <throw expression> <expresión throw> @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 267da2bf78f42..05e3c8d60662b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -152,6 +152,11 @@ Erreur de syntaxe de ligne de commande : '{0}' est une valeur non valide pour l'option '{1}'. La valeur doit se présenter sous la forme '{2}'. + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation implémentation d'interface par défaut @@ -1364,11 +1374,21 @@ <Null> + + notnull + notnull + + constraints for override and explicit interface implementation methods contraintes des méthodes d'implémentation d'interface par remplacement et explicites + + struct + struct + + <throw expression> <expression throw> @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 5c66bfbb6fad6..fcd7ef4a114f5 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -152,6 +152,11 @@ Errore di sintassi della riga di comando: '{0}' non è un valore valido per l'opzione '{1}'. Il valore deve essere espresso nel formato '{2}'. + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation implementazione di interfaccia predefinita @@ -1364,11 +1374,21 @@ <Null> + + notnull + notnull + + constraints for override and explicit interface implementation methods vincoli per i metodi di override e di implementazione esplicita dell'interfaccia + + struct + struct + + <throw expression> <espressione throw> @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 1ce4645e28c3f..9ccb15eb4c1af 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -152,6 +152,11 @@ コマンドライン構文エラー: '{0}' は、'{1}' オプションの有効な値ではありません。値は '{2}' の形式にする必要があります。 + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation 既定のインターフェイスの実装 @@ -1364,11 +1374,21 @@ <null> + + notnull + notnull + + constraints for override and explicit interface implementation methods オーバーライドおよび明示的なインターフェイスの実装メソッドの制約 + + struct + struct + + <throw expression> <スロー式> @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index e1288e3b47b37..f25e5829f71a4 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -152,6 +152,11 @@ 명령줄 구문 오류: '{0}'은(는) '{1}' 옵션에 유효한 값이 아닙니다. 값은 '{2}' 형식이어야 합니다. + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation 기본 인터페이스 구현 @@ -1364,11 +1374,21 @@ <null> + + notnull + notnull + + constraints for override and explicit interface implementation methods 재정의 및 명시적 인터페이스 구현 메서드에 대한 제약 조건 + + struct + struct + + <throw expression> <Throw 식> @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 3b4a2d428096b..4b8607c8280a1 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -152,6 +152,11 @@ Błąd składni wiersza polecenia: „{0}” nie jest prawidłową wartością dla opcji „{1}”. Wartość musi mieć postać „{2}”. + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation domyślna implementacja interfejsu @@ -1364,11 +1374,21 @@ <null> + + notnull + notnull + + constraints for override and explicit interface implementation methods ograniczenia dla przesłonięć i jawnych metod implementacji interfejsu + + struct + struct + + <throw expression> <wyrażenie throw> @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index c08aea3759945..f2b0465eba5ae 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -152,6 +152,11 @@ Erro de sintaxe de linha de comando: '{0}' não é um valor válido para a opção '{1}'. O valor precisa estar no formato '{2}'. + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1112,6 +1117,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation implementação de interface padrão @@ -1362,11 +1372,21 @@ <nulo> + + notnull + notnull + + constraints for override and explicit interface implementation methods restrições para métodos de substituição e de implementação explícita da interface + + struct + struct + + <throw expression> <expressão throw> @@ -1387,6 +1407,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index b71df5fde3119..700c50546cfc4 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -152,6 +152,11 @@ Ошибка в синтаксисе командной строки: "{0}" не является допустимым значением для параметра "{1}". Значение должно иметь форму "{2}". + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation реализация интерфейса по умолчанию @@ -1364,11 +1374,21 @@ <NULL> + + notnull + notnull + + constraints for override and explicit interface implementation methods ограничения для методов переопределения и явной реализации интерфейса + + struct + struct + + <throw expression> <выражение throw> @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 71286ed2418ac..66531fec5a14e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -152,6 +152,11 @@ Komut satırı söz dizimi hatası: '{0}', '{1}' seçeneği için geçerli bir değer değil. Değer '{2}' biçiminde olmalıdır. + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation varsayılan arabirim uygulaması @@ -1364,11 +1374,21 @@ <null> + + notnull + notnull + + constraints for override and explicit interface implementation methods geçersiz kılma ve açık arabirim uygulama yöntemleri için kısıtlamalar + + struct + struct + + <throw expression> <throw ifadesi> @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index b9cdde0c4dc84..856165bd5c7a2 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -152,6 +152,11 @@ 命令行语法错误:“{0}”不是“{1}”选项的有效值。值的格式必须为 "{2}"。 + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation 默认接口实现 @@ -1364,11 +1374,21 @@ <null> + + notnull + notnull + + constraints for override and explicit interface implementation methods 重写和显式接口实现方法的约束 + + struct + struct + + <throw expression> <throw 表达式> @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 0293eaf68bc9f..4e1fcbd1f0dbd 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -152,6 +152,11 @@ 命令列語法錯誤: '{0}' 對 '{1}' 選項而言不是有效的值。此值的格式必須是 '{2}'。 + + The '{0}' constraint cannot be combined with the '{1}' constraint + The '{0}' constraint cannot be combined with the '{1}' constraint + + Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -1114,6 +1119,11 @@ Visual C# Compiler Options + + class + class + + default interface implementation 預設介面實作 @@ -1364,11 +1374,21 @@ <null> + + notnull + notnull + + constraints for override and explicit interface implementation methods 適用於覆寫和明確介面實作方法的條件約束 + + struct + struct + + <throw expression> <throw 運算式> @@ -1389,6 +1409,11 @@ top-level statements + + unmanaged + unmanaged + + <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/GenericConstraintsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/GenericConstraintsTests.cs index 43d1997792802..b79bb9e82de76 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_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "class").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_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "struct").WithLocation(1, 40)); var typeParameter = c.GlobalNamespace.GetTypeMember("Test").TypeParameters.Single(); Assert.False(typeParameter.HasUnmanagedTypeConstraint); @@ -4152,5 +4152,146 @@ 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 : unmanaged, struct, class, notnull +{ + void M3() where T2 : unmanaged, struct, class, notnull {} +} +class C4 where T1 : notnull, struct, unmanaged, class +{ + void M4() where T2 : notnull, struct, unmanaged, class {} +} +"); + + comp.VerifyDiagnostics( + // (2,32): error CS8869: The 'struct' constraint cannot be combined with the 'class' constraint + // class C1 where T1 : class, struct, unmanaged, notnull + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "class").WithLocation(2, 32), + // (2,40): error CS8869: The 'unmanaged' constraint cannot be combined with the 'class' constraint + // class C1 where T1 : class, struct, unmanaged, notnull + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "class").WithLocation(2, 40), + // (2,51): error CS8869: The 'notnull' constraint cannot be combined with the 'class' constraint + // class C1 where T1 : class, struct, unmanaged, notnull + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "class").WithLocation(2, 51), + // (4,37): error CS8869: The 'struct' constraint cannot be combined with the 'class' constraint + // void M1() where T2 : class, struct, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "class").WithLocation(4, 37), + // (4,45): error CS8869: The 'unmanaged' constraint cannot be combined with the 'class' constraint + // void M1() where T2 : class, struct, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "class").WithLocation(4, 45), + // (4,56): error CS8869: The 'notnull' constraint cannot be combined with the 'class' constraint + // void M1() where T2 : class, struct, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "class").WithLocation(4, 56), + // (6,33): error CS8869: The 'class' constraint cannot be combined with the 'struct' constraint + // class C2 where T1 : struct, class, unmanaged, notnull + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").WithLocation(6, 33), + // (6,40): error CS8869: The 'unmanaged' constraint cannot be combined with the 'struct' constraint + // class C2 where T1 : struct, class, unmanaged, notnull + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "struct").WithLocation(6, 40), + // (6,51): error CS8869: The 'notnull' constraint cannot be combined with the 'struct' constraint + // class C2 where T1 : struct, class, unmanaged, notnull + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "struct").WithLocation(6, 51), + // (8,38): error CS8869: The 'class' constraint cannot be combined with the 'struct' constraint + // void M2() where T2 : struct, class, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").WithLocation(8, 38), + // (8,45): error CS8869: The 'unmanaged' constraint cannot be combined with the 'struct' constraint + // void M2() where T2 : struct, class, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "struct").WithLocation(8, 45), + // (8,56): error CS8869: The 'notnull' constraint cannot be combined with the 'struct' constraint + // void M2() where T2 : struct, class, unmanaged, notnull {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "struct").WithLocation(8, 56), + // (10,36): error CS8869: The 'struct' constraint cannot be combined with the 'unmanaged' constraint + // class C3 where T1 : unmanaged, struct, class, notnull + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "unmanaged").WithLocation(10, 36), + // (10,44): error CS8869: The 'class' constraint cannot be combined with the 'unmanaged' constraint + // class C3 where T1 : unmanaged, struct, class, notnull + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "unmanaged").WithLocation(10, 44), + // (10,51): error CS8869: The 'notnull' constraint cannot be combined with the 'unmanaged' constraint + // class C3 where T1 : unmanaged, struct, class, notnull + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "unmanaged").WithLocation(10, 51), + // (12,41): error CS8869: The 'struct' constraint cannot be combined with the 'unmanaged' constraint + // void M3() where T2 : unmanaged, struct, class, notnull {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "unmanaged").WithLocation(12, 41), + // (12,49): error CS8869: The 'class' constraint cannot be combined with the 'unmanaged' constraint + // void M3() where T2 : unmanaged, struct, class, notnull {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "unmanaged").WithLocation(12, 49), + // (12,56): error CS8869: The 'notnull' constraint cannot be combined with the 'unmanaged' constraint + // void M3() where T2 : unmanaged, struct, class, notnull {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "unmanaged").WithLocation(12, 56), + // (14,34): error CS8869: The 'struct' constraint cannot be combined with the 'notnull' constraint + // class C4 where T1 : notnull, struct, unmanaged, class + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "notnull").WithLocation(14, 34), + // (14,42): error CS8869: The 'unmanaged' constraint cannot be combined with the 'notnull' constraint + // class C4 where T1 : notnull, struct, unmanaged, class + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "notnull").WithLocation(14, 42), + // (14,53): error CS8869: The 'class' constraint cannot be combined with the 'notnull' constraint + // class C4 where T1 : notnull, struct, unmanaged, class + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "notnull").WithLocation(14, 53), + // (16,39): error CS8869: The 'struct' constraint cannot be combined with the 'notnull' constraint + // void M4() where T2 : notnull, struct, unmanaged, class {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "notnull").WithLocation(16, 39), + // (16,47): error CS8869: The 'unmanaged' constraint cannot be combined with the 'notnull' constraint + // void M4() where T2 : notnull, struct, unmanaged, class {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "notnull").WithLocation(16, 47), + // (16,58): error CS8869: The 'class' constraint cannot be combined with the 'notnull' constraint + // void M4() where T2 : notnull, struct, unmanaged, class {} + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "notnull").WithLocation(16, 58) + ); + } + + [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..a12709cdb25b1 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 CS8869: The 'class' constraint cannot be combined with the 'struct' constraint // public override void Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(8, 60)); + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").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 CS8869: The 'struct' constraint cannot be combined with the 'class' constraint // public override void Goo(T value) where T : class, struct { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "struct").WithLocation(8, 59)); + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "class").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 CS8869: The 'class' constraint cannot be combined with the 'struct' constraint // public override void Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(9, 60)); + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").WithLocation(9, 60)); } [Fact] @@ -9086,9 +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 CS8869: The 'class' constraint cannot be combined with the 'struct' constraint // void I.Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(8, 46) + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").WithLocation(8, 46) ); } @@ -9109,9 +9109,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 CS8869: The 'struct' constraint cannot be combined with the 'class' constraint // void I.Goo(T value) where T : class, struct { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "struct").WithLocation(8, 45)); + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "class").WithLocation(8, 45)); } [Fact] @@ -9129,9 +9129,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 CS8869: The 'class' constraint cannot be combined with the 'struct' constraint // void I.Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(9, 46)); + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").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..38f46faa519b1 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 CS8869: The 'struct' constraint cannot be combined with the 'notnull' constraint // 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_CannotCombineTypeConstraints, "struct").WithArguments("struct", "notnull").WithLocation(8, 59), + // (4,58): error CS8869: The 'notnull' constraint cannot be combined with the 'struct' constraint // public static void F1(T1? t1) where T1 : struct, notnull - Diagnostic(ErrorCode.ERR_NotNullConstraintMustBeFirst, "notnull").WithLocation(4, 58) + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "struct").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 CS8869: The 'notnull' constraint cannot be combined with the 'class' constraint // 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_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "class").WithLocation(4, 57), + // (8,59): error CS8869: The 'class' constraint cannot be combined with the 'notnull' constraint // public static void F2(T2? t2) where T2 : notnull, class - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(8, 59) + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "notnull").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 CS8869: The 'notnull' constraint cannot be combined with the 'class' constraint // 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_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "class").WithLocation(4, 58), + // (8,59): error CS8869: The 'class' constraint cannot be combined with the 'notnull' constraint // public static void F2(T2? t2) where T2 : notnull, class? - Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(8, 59) + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "notnull").WithLocation(8, 59) ); var m = comp.SourceModule; From fdfbaefff74f24d33c4d9f00627eed02560e1bfb Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Sat, 13 Jun 2020 21:25:51 -0700 Subject: [PATCH 2/4] Update baselines. --- .../Test/Syntax/Parsing/ParserErrorMessageTests.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs index 9894a5d168590..f681741ac7f90 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs @@ -874,7 +874,7 @@ public void CS0449ERR_RefValBoundMustBeFirst() interface I {} class C4 { - public void F1() where T : class, struct, I {} // CS0449 + public void F1() where T : class, struct, I {} // CS8869 public void F2() where T : I, struct {} // CS0449 public void F3() where T : I, class {} // CS0449 // OK @@ -884,11 +884,14 @@ 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), + // (5,41): error CS8869: The 'struct' constraint cannot be combined with the 'class' constraint + // public void F1() where T : class, struct, I {} // CS8869 + Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "class").WithLocation(5, 41), // (6,37): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + // public void F2() where T : I, struct {} // CS0449 Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "struct").WithLocation(6, 37), // (7,37): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + // public void F3() where T : I, class {} // CS0449 Diagnostic(ErrorCode.ERR_RefValBoundMustBeFirst, "class").WithLocation(7, 37)); } From 388cc58a428465fd33cfd516dd5476ca2eed0211 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Wed, 17 Jun 2020 18:17:12 -0700 Subject: [PATCH 3/4] Simplify handling of error messages. --- .../Portable/Binder/Binder_Constraints.cs | 26 +---- .../CSharp/Portable/CSharpResources.resx | 25 +--- .../CSharp/Portable/Errors/ErrorCode.cs | 7 +- .../CSharp/Portable/Errors/MessageID.cs | 4 - .../Portable/xlf/CSharpResources.cs.xlf | 45 +------- .../Portable/xlf/CSharpResources.de.xlf | 45 +------- .../Portable/xlf/CSharpResources.es.xlf | 45 +------- .../Portable/xlf/CSharpResources.fr.xlf | 45 +------- .../Portable/xlf/CSharpResources.it.xlf | 45 +------- .../Portable/xlf/CSharpResources.ja.xlf | 45 +------- .../Portable/xlf/CSharpResources.ko.xlf | 45 +------- .../Portable/xlf/CSharpResources.pl.xlf | 45 +------- .../Portable/xlf/CSharpResources.pt-BR.xlf | 45 +------- .../Portable/xlf/CSharpResources.ru.xlf | 45 +------- .../Portable/xlf/CSharpResources.tr.xlf | 45 +------- .../Portable/xlf/CSharpResources.zh-Hans.xlf | 45 +------- .../Portable/xlf/CSharpResources.zh-Hant.xlf | 45 +------- .../CSharp/Test/Emit/CodeGen/SwitchTests.cs | 2 +- .../Semantics/GenericConstraintsTests.cs | 108 ++++++------------ .../Semantics/InheritanceBindingTests.cs | 12 +- .../Semantics/NullableReferenceTypesTests.cs | 28 ++--- .../Syntax/Parsing/ParserErrorMessageTests.cs | 18 +-- 22 files changed, 141 insertions(+), 674 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs index df6006e9784c5..363c5a6ad4fae 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs @@ -126,7 +126,6 @@ internal ImmutableArray BindTypeParameterConstrai Debug.Assert(!InExecutableBinder); // Cannot eagerly report diagnostics handled by LazyMissingNonNullTypesContextDiagnosticInfo bool hasTypeLikeConstraint = false; bool reportedOverrideWithConstraints = false; - MessageID? firstTypeConstraintString = null; for (int i = 0, n = constraintsSyntax.Count; i < n; i++) { @@ -140,7 +139,7 @@ internal ImmutableArray BindTypeParameterConstrai { if (!reportedOverrideWithConstraints) { - reportNotFirstOrCannotCombine(diagnostics, syntax.GetFirstToken().GetLocation(), ErrorCode.ERR_RefValBoundMustBeFirst, MessageID.IDS_Class, firstTypeConstraintString); + diagnostics.Add(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, syntax.GetFirstToken().GetLocation()); } if (isForOverride && (constraints & (TypeParameterConstraintKind.ValueType | TypeParameterConstraintKind.ReferenceType)) != 0) @@ -149,7 +148,6 @@ internal ImmutableArray BindTypeParameterConstrai } } - firstTypeConstraintString ??= MessageID.IDS_Class; var constraintSyntax = (ClassOrStructConstraintSyntax)syntax; SyntaxToken questionToken = constraintSyntax.QuestionToken; if (questionToken.IsKind(SyntaxKind.QuestionToken)) @@ -182,7 +180,7 @@ internal ImmutableArray BindTypeParameterConstrai { if (!reportedOverrideWithConstraints) { - reportNotFirstOrCannotCombine(diagnostics, syntax.GetFirstToken().GetLocation(), ErrorCode.ERR_RefValBoundMustBeFirst, MessageID.IDS_Struct, firstTypeConstraintString); + diagnostics.Add(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, syntax.GetFirstToken().GetLocation()); } if (isForOverride && (constraints & (TypeParameterConstraintKind.ValueType | TypeParameterConstraintKind.ReferenceType)) != 0) @@ -191,7 +189,6 @@ internal ImmutableArray BindTypeParameterConstrai } } - firstTypeConstraintString ??= MessageID.IDS_Struct; constraints |= TypeParameterConstraintKind.ValueType; continue; case SyntaxKind.ConstructorConstraint: @@ -242,12 +239,10 @@ internal ImmutableArray BindTypeParameterConstrai case ConstraintContextualKeyword.Unmanaged: if (i != 0) { - reportNotFirstOrCannotCombine(diagnostics, typeSyntax.GetLocation(), ErrorCode.ERR_UnmanagedConstraintMustBeFirst, MessageID.IDS_Unmanaged, firstTypeConstraintString); + diagnostics.Add(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, typeSyntax.GetLocation()); continue; } - firstTypeConstraintString ??= MessageID.IDS_Unmanaged; - // This should produce diagnostics if the types are missing GetWellKnownType(WellKnownType.System_Runtime_InteropServices_UnmanagedType, diagnostics, typeSyntax); GetSpecialType(SpecialType.System_ValueType, diagnostics, typeSyntax); @@ -258,10 +253,9 @@ internal ImmutableArray BindTypeParameterConstrai case ConstraintContextualKeyword.NotNull: if (i != 0) { - reportNotFirstOrCannotCombine(diagnostics, typeSyntax.GetLocation(), ErrorCode.ERR_NotNullConstraintMustBeFirst, MessageID.IDS_Notnull, firstTypeConstraintString); + diagnostics.Add(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, typeSyntax.GetLocation()); } - firstTypeConstraintString ??= MessageID.IDS_Notnull; constraints |= TypeParameterConstraintKind.NotNull; continue; @@ -298,18 +292,6 @@ static void reportOverrideWithConstraints(ref bool reportedOverrideWithConstrain reportedOverrideWithConstraints = true; } } - - static void reportNotFirstOrCannotCombine(DiagnosticBag diagnostics, Location constraintLocation, ErrorCode notFirstDiagnostic, MessageID currentConstraintString, MessageID? firstConstraintString) - { - if (firstConstraintString is MessageID firstConstraint) - { - diagnostics.Add(ErrorCode.ERR_CannotCombineTypeConstraints, constraintLocation, currentConstraintString.Localize(), firstConstraint.Localize()); - } - else - { - diagnostics.Add(notFirstDiagnostic, constraintLocation); - } - } } internal ImmutableArray GetDefaultTypeParameterConstraintClauses(TypeParameterListSyntax typeParameterList) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index b7c56ca1a37d0..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. @@ -6262,19 +6256,4 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ A copy constructor in a record must call a copy constructor of the base, or a parameterless object constructor if the record inherits from object. - - class - - - struct - - - unmanaged - - - notnull - - - The '{0}' constraint cannot be combined with the '{1}' constraint - diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index 4f9d29e732d6f..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, @@ -1835,7 +1835,6 @@ internal enum ErrorCode ERR_BadRecordMemberForPositionalParameter = 8866, ERR_NoCopyConstructorInBaseType = 8867, ERR_CopyConstructorMustInvokeBaseCopyConstructor = 8868, - ERR_CannotCombineTypeConstraints = 8869, #endregion diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs index 569060b6d242b..fd3b09596ef28 100644 --- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs +++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs @@ -206,10 +206,6 @@ internal enum MessageID IDS_FeatureInitOnlySetters = MessageBase + 12781, IDS_FeatureRecords = MessageBase + 12782, IDS_FeatureNullPointerConstantPattern = MessageBase + 12783, - IDS_Class = MessageBase + 12784, - IDS_Struct = MessageBase + 12785, - IDS_Unmanaged = MessageBase + 12786, - IDS_Notnull = MessageBase + 12787, } // Message IDs may refer to strings that need to be localized. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 0134a34ad2bd1..4050a575341f8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -152,11 +152,6 @@ Chyba syntaxe příkazového řádku: {0} není platná hodnota možnosti {1}. Hodnota musí mít tvar {2}. - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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. @@ -727,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() @@ -757,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}. @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation implementace výchozího rozhraní @@ -1374,21 +1359,11 @@ <null> - - notnull - notnull - - constraints for override and explicit interface implementation methods omezení pro metody přepsání a explicitní implementace rozhraní - - struct - struct - - <throw expression> <výraz throw> @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 008a4101e9d83..dfb17d10f5255 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -152,11 +152,6 @@ Fehler in der Befehlszeilensyntax: "{0}" ist kein gültiger Wert für die Option "{1}". Der Wert muss im Format "{2}" vorliegen. - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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. @@ -727,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() @@ -757,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. @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation Standardschnittstellenimplementierung @@ -1374,21 +1359,11 @@ <NULL> - - notnull - notnull - - constraints for override and explicit interface implementation methods Einschränkungen für Außerkraftsetzung und explizite Schnittstellenimplementierungsmethoden - - struct - struct - - <throw expression> throw-Ausdruck @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 6b96c7f8348ac..1b24fea19dca8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -152,11 +152,6 @@ Error de sintaxis de la línea de comandos: "{0}" no es un valor válido para la opción "{1}". El valor debe tener el formato "{2}". - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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". @@ -727,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() @@ -757,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}" @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation implementación de interfaz predeterminada @@ -1374,21 +1359,11 @@ <NULL> - - notnull - notnull - - constraints for override and explicit interface implementation methods restricciones para métodos de implementación de interfaz explícita e invalidación - - struct - struct - - <throw expression> <expresión throw> @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 05e3c8d60662b..135871215fb18 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -152,11 +152,6 @@ Erreur de syntaxe de ligne de commande : '{0}' est une valeur non valide pour l'option '{1}'. La valeur doit se présenter sous la forme '{2}'. - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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 @@ -727,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() @@ -757,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}' @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation implémentation d'interface par défaut @@ -1374,21 +1359,11 @@ <Null> - - notnull - notnull - - constraints for override and explicit interface implementation methods contraintes des méthodes d'implémentation d'interface par remplacement et explicites - - struct - struct - - <throw expression> <expression throw> @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 fcd7ef4a114f5..fa54f8ac8ad33 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -152,11 +152,6 @@ Errore di sintassi della riga di comando: '{0}' non è un valore valido per l'opzione '{1}'. Il valore deve essere espresso nel formato '{2}'. - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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' @@ -727,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() @@ -757,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}' @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation implementazione di interfaccia predefinita @@ -1374,21 +1359,11 @@ <Null> - - notnull - notnull - - constraints for override and explicit interface implementation methods vincoli per i metodi di override e di implementazione esplicita dell'interfaccia - - struct - struct - - <throw expression> <espressione throw> @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 9ccb15eb4c1af..06c2ffec95d0b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -152,11 +152,6 @@ コマンドライン構文エラー: '{0}' は、'{1}' オプションの有効な値ではありません。値は '{2}' の形式にする必要があります。 - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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' のいずれかが必要でした @@ -727,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() @@ -757,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 非許容の値型でなければなりません @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation 既定のインターフェイスの実装 @@ -1374,21 +1359,11 @@ <null> - - notnull - notnull - - constraints for override and explicit interface implementation methods オーバーライドおよび明示的なインターフェイスの実装メソッドの制約 - - struct - struct - - <throw expression> <スロー式> @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 f25e5829f71a4..495da25bbde98 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -152,11 +152,6 @@ 명령줄 구문 오류: '{0}'은(는) '{1}' 옵션에 유효한 값이 아닙니다. 값은 '{2}' 형식이어야 합니다. - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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'가 필요합니다. @@ -727,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() @@ -757,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을 허용하지 않는 값 형식이어야 합니다. @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation 기본 인터페이스 구현 @@ -1374,21 +1359,11 @@ <null> - - notnull - notnull - - constraints for override and explicit interface implementation methods 재정의 및 명시적 인터페이스 구현 메서드에 대한 제약 조건 - - struct - struct - - <throw expression> <Throw 식> @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 4b8607c8280a1..376caf6c83b92 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -152,11 +152,6 @@ Błąd składni wiersza polecenia: „{0}” nie jest prawidłową wartością dla opcji „{1}”. Wartość musi mieć postać „{2}”. - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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” @@ -727,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() @@ -757,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}” @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation domyślna implementacja interfejsu @@ -1374,21 +1359,11 @@ <null> - - notnull - notnull - - constraints for override and explicit interface implementation methods ograniczenia dla przesłonięć i jawnych metod implementacji interfejsu - - struct - struct - - <throw expression> <wyrażenie throw> @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 f2b0465eba5ae..b377ab9b8a23d 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -152,11 +152,6 @@ Erro de sintaxe de linha de comando: '{0}' não é um valor válido para a opção '{1}'. O valor precisa estar no formato '{2}'. - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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' @@ -727,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() @@ -757,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}' @@ -1117,11 +1107,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation implementação de interface padrão @@ -1372,21 +1357,11 @@ <nulo> - - notnull - notnull - - constraints for override and explicit interface implementation methods restrições para métodos de substituição e de implementação explícita da interface - - struct - struct - - <throw expression> <expressão throw> @@ -1407,11 +1382,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4052,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 700c50546cfc4..1f60a79af7a38 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -152,11 +152,6 @@ Ошибка в синтаксисе командной строки: "{0}" не является допустимым значением для параметра "{1}". Значение должно иметь форму "{2}". - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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" @@ -727,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() @@ -757,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. @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation реализация интерфейса по умолчанию @@ -1374,21 +1359,11 @@ <NULL> - - notnull - notnull - - constraints for override and explicit interface implementation methods ограничения для методов переопределения и явной реализации интерфейса - - struct - struct - - <throw expression> <выражение throw> @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 66531fec5a14e..ce7fb96ede2c6 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -152,11 +152,6 @@ Komut satırı söz dizimi hatası: '{0}', '{1}' seçeneği için geçerli bir değer değil. Değer '{2}' biçiminde olmalıdır. - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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 @@ -727,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() @@ -757,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 @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation varsayılan arabirim uygulaması @@ -1374,21 +1359,11 @@ <null> - - notnull - notnull - - constraints for override and explicit interface implementation methods geçersiz kılma ve açık arabirim uygulama yöntemleri için kısıtlamalar - - struct - struct - - <throw expression> <throw ifadesi> @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 856165bd5c7a2..87d3299e67caa 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -152,11 +152,6 @@ 命令行语法错误:“{0}”不是“{1}”选项的有效值。值的格式必须为 "{2}"。 - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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" @@ -727,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() @@ -757,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}” @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation 默认接口实现 @@ -1374,21 +1359,11 @@ <null> - - notnull - notnull - - constraints for override and explicit interface implementation methods 重写和显式接口实现方法的约束 - - struct - struct - - <throw expression> <throw 表达式> @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 4e1fcbd1f0dbd..17f4495781ef2 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -152,11 +152,6 @@ 命令列語法錯誤: '{0}' 對 '{1}' 選項而言不是有效的值。此值的格式必須是 '{2}'。 - - The '{0}' constraint cannot be combined with the '{1}' constraint - The '{0}' constraint cannot be combined with the '{1}' constraint - - Cannot convert &method group '{0}' to delegate type '{0}'. Cannot convert &method group '{0}' to delegate type '{0}'. @@ -517,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' @@ -727,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() @@ -757,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}' @@ -1119,11 +1109,6 @@ Visual C# Compiler Options - - class - class - - default interface implementation 預設介面實作 @@ -1374,21 +1359,11 @@ <null> - - notnull - notnull - - constraints for override and explicit interface implementation methods 適用於覆寫和明確介面實作方法的條件約束 - - struct - struct - - <throw expression> <throw 運算式> @@ -1409,11 +1384,6 @@ top-level statements - - unmanaged - unmanaged - - <!-- Badly formed XML comment ignored for member "{0}" --> <!-- Badly formed XML comment ignored for member "{0}" --> @@ -4054,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 b79bb9e82de76..d2e972169eee9 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/GenericConstraintsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/GenericConstraintsTests.cs @@ -1829,7 +1829,7 @@ public void UnmanagedConstraint_Compilation_ReferenceType() c.VerifyDiagnostics( // (1,39): error CS8869: The 'unmanaged' constraint cannot be combined with the 'class' constraint // public class Test where T : class, unmanaged {} - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "class").WithLocation(1, 39)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "unmanaged").WithLocation(1, 39)); var typeParameter = c.GlobalNamespace.GetTypeMember("Test").TypeParameters.Single(); Assert.False(typeParameter.HasUnmanagedTypeConstraint); @@ -1847,7 +1847,7 @@ public void UnmanagedConstraint_Compilation_ValueType() c.VerifyDiagnostics( // (1,40): error CS8869: The 'unmanaged' constraint cannot be combined with the 'struct' constraint // public class Test where T : struct, unmanaged {} - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "struct").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] @@ -4165,89 +4165,55 @@ class C2 where T1 : struct, class, unmanaged, notnull { void M2() where T2 : struct, class, unmanaged, notnull {} } -class C3 where T1 : unmanaged, struct, class, notnull +class C3 where T1 : class, class { - void M3() where T2 : unmanaged, struct, class, notnull {} -} -class C4 where T1 : notnull, struct, unmanaged, class -{ - void M4() where T2 : notnull, struct, unmanaged, class {} + void M3() where T2 : class, class {} } "); comp.VerifyDiagnostics( - // (2,32): error CS8869: The 'struct' constraint cannot be combined with the 'class' constraint + // (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_CannotCombineTypeConstraints, "struct").WithArguments("struct", "class").WithLocation(2, 32), - // (2,40): error CS8869: The 'unmanaged' constraint cannot be combined with the 'class' constraint + 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_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "class").WithLocation(2, 40), - // (2,51): error CS8869: The 'notnull' constraint cannot be combined with the 'class' constraint + 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_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "class").WithLocation(2, 51), - // (4,37): error CS8869: The 'struct' constraint cannot be combined with the 'class' constraint + 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_CannotCombineTypeConstraints, "struct").WithArguments("struct", "class").WithLocation(4, 37), - // (4,45): error CS8869: The 'unmanaged' constraint cannot be combined with the 'class' constraint + 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_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "class").WithLocation(4, 45), - // (4,56): error CS8869: The 'notnull' constraint cannot be combined with the 'class' constraint + 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_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "class").WithLocation(4, 56), - // (6,33): error CS8869: The 'class' constraint cannot be combined with the 'struct' constraint + 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_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").WithLocation(6, 33), - // (6,40): error CS8869: The 'unmanaged' constraint cannot be combined with the 'struct' constraint + 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_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "struct").WithLocation(6, 40), - // (6,51): error CS8869: The 'notnull' constraint cannot be combined with the 'struct' constraint + 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_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "struct").WithLocation(6, 51), - // (8,38): error CS8869: The 'class' constraint cannot be combined with the 'struct' constraint + 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_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").WithLocation(8, 38), - // (8,45): error CS8869: The 'unmanaged' constraint cannot be combined with the 'struct' constraint + 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_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "struct").WithLocation(8, 45), - // (8,56): error CS8869: The 'notnull' constraint cannot be combined with the 'struct' constraint + 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_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "struct").WithLocation(8, 56), - // (10,36): error CS8869: The 'struct' constraint cannot be combined with the 'unmanaged' constraint - // class C3 where T1 : unmanaged, struct, class, notnull - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "unmanaged").WithLocation(10, 36), - // (10,44): error CS8869: The 'class' constraint cannot be combined with the 'unmanaged' constraint - // class C3 where T1 : unmanaged, struct, class, notnull - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "unmanaged").WithLocation(10, 44), - // (10,51): error CS8869: The 'notnull' constraint cannot be combined with the 'unmanaged' constraint - // class C3 where T1 : unmanaged, struct, class, notnull - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "unmanaged").WithLocation(10, 51), - // (12,41): error CS8869: The 'struct' constraint cannot be combined with the 'unmanaged' constraint - // void M3() where T2 : unmanaged, struct, class, notnull {} - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "unmanaged").WithLocation(12, 41), - // (12,49): error CS8869: The 'class' constraint cannot be combined with the 'unmanaged' constraint - // void M3() where T2 : unmanaged, struct, class, notnull {} - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "unmanaged").WithLocation(12, 49), - // (12,56): error CS8869: The 'notnull' constraint cannot be combined with the 'unmanaged' constraint - // void M3() where T2 : unmanaged, struct, class, notnull {} - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "unmanaged").WithLocation(12, 56), - // (14,34): error CS8869: The 'struct' constraint cannot be combined with the 'notnull' constraint - // class C4 where T1 : notnull, struct, unmanaged, class - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "notnull").WithLocation(14, 34), - // (14,42): error CS8869: The 'unmanaged' constraint cannot be combined with the 'notnull' constraint - // class C4 where T1 : notnull, struct, unmanaged, class - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "notnull").WithLocation(14, 42), - // (14,53): error CS8869: The 'class' constraint cannot be combined with the 'notnull' constraint - // class C4 where T1 : notnull, struct, unmanaged, class - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "notnull").WithLocation(14, 53), - // (16,39): error CS8869: The 'struct' constraint cannot be combined with the 'notnull' constraint - // void M4() where T2 : notnull, struct, unmanaged, class {} - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "notnull").WithLocation(16, 39), - // (16,47): error CS8869: The 'unmanaged' constraint cannot be combined with the 'notnull' constraint - // void M4() where T2 : notnull, struct, unmanaged, class {} - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "unmanaged").WithArguments("unmanaged", "notnull").WithLocation(16, 47), - // (16,58): error CS8869: The 'class' constraint cannot be combined with the 'notnull' constraint - // void M4() where T2 : notnull, struct, unmanaged, class {} - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "notnull").WithLocation(16, 58) + 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) ); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs index a12709cdb25b1..4f6e9c41c7410 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs @@ -9024,7 +9024,7 @@ 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 CS8869: The 'class' constraint cannot be combined with the 'struct' constraint // public override void Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").WithLocation(8, 60)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).WithLocation(8, 60)); } [Fact] @@ -9046,7 +9046,7 @@ 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 CS8869: The 'struct' constraint cannot be combined with the 'class' constraint // public override void Goo(T value) where T : class, struct { } - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "class").WithLocation(8, 59)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).WithLocation(8, 59)); } [Fact] @@ -9066,7 +9066,7 @@ public override void Goo(T value) where T : struct, class { } var comp = CreateCompilation(source).VerifyDiagnostics( // (9,60): error CS8869: The 'class' constraint cannot be combined with the 'struct' constraint // public override void Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").WithLocation(9, 60)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).WithLocation(9, 60)); } [Fact] @@ -9088,7 +9088,7 @@ void I.Goo(T value) where T : struct, class { } Diagnostic(ErrorCode.ERR_InterfaceMemberNotFound, "Goo").WithArguments("C.Goo(T)").WithLocation(8, 12), // (8,46): error CS8869: The 'class' constraint cannot be combined with the 'struct' constraint // void I.Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").WithLocation(8, 46) + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).WithLocation(8, 46) ); } @@ -9111,7 +9111,7 @@ void I.Goo(T value) where T : class, struct { } Diagnostic(ErrorCode.ERR_InterfaceMemberNotFound, "Goo").WithArguments("C.Goo(T)").WithLocation(8, 12), // (8,45): error CS8869: The 'struct' constraint cannot be combined with the 'class' constraint // void I.Goo(T value) where T : class, struct { } - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "class").WithLocation(8, 45)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).WithLocation(8, 45)); } [Fact] @@ -9131,7 +9131,7 @@ void I.Goo(T value) where T : struct, class { } var comp = CreateCompilation(source).VerifyDiagnostics( // (9,46): error CS8869: The 'class' constraint cannot be combined with the 'struct' constraint // void I.Goo(T value) where T : struct, class { } - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "class").WithArguments("class", "struct").WithLocation(9, 46)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).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 38f46faa519b1..c0ba167fed8c4 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 CS8869: The 'struct' constraint cannot be combined with the 'notnull' constraint + // (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_CannotCombineTypeConstraints, "struct").WithArguments("struct", "notnull").WithLocation(8, 59), - // (4,58): error CS8869: The 'notnull' constraint cannot be combined with the 'struct' constraint + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).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_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "struct").WithLocation(4, 58) + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).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 CS8869: The 'notnull' constraint cannot be combined with the 'class' constraint + // (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_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "class").WithLocation(4, 57), - // (8,59): error CS8869: The 'class' constraint cannot be combined with the 'notnull' constraint + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).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_CannotCombineTypeConstraints, "class").WithArguments("class", "notnull").WithLocation(8, 59) + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).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 CS8869: The 'notnull' constraint cannot be combined with the 'class' constraint + // (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_CannotCombineTypeConstraints, "notnull").WithArguments("notnull", "class").WithLocation(4, 58), - // (8,59): error CS8869: The 'class' constraint cannot be combined with the 'notnull' constraint + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).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_CannotCombineTypeConstraints, "class").WithArguments("class", "notnull").WithLocation(8, 59) + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst).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 f681741ac7f90..42ed9edd86061 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs @@ -868,13 +868,13 @@ public static void Main() } [Fact] - public void CS0449ERR_RefValBoundMustBeFirst() + public void CS0449ERR_TypeConstraintsMustBeUniqueAndFirst() { var test = @" interface I {} class C4 { - public void F1() where T : class, struct, I {} // CS8869 + public void F1() where T : class, struct, I {} // CS0449 public void F2() where T : I, struct {} // CS0449 public void F3() where T : I, class {} // CS0449 // OK @@ -884,15 +884,15 @@ public void F6() where T : I {} } "; CreateCompilation(test).VerifyDiagnostics( - // (5,41): error CS8869: The 'struct' constraint cannot be combined with the 'class' constraint - // public void F1() where T : class, struct, I {} // CS8869 - Diagnostic(ErrorCode.ERR_CannotCombineTypeConstraints, "struct").WithArguments("struct", "class").WithLocation(5, 41), - // (6,37): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + // (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_RefValBoundMustBeFirst, "struct").WithLocation(6, 37), - // (7,37): error CS0449: The 'class' or 'struct' constraint must come before any other constraints + 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_RefValBoundMustBeFirst, "class").WithLocation(7, 37)); + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(7, 37)); } [Fact] From accbfd902943213256f5c34252517d6b4fe89cbf Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Thu, 18 Jun 2020 11:08:57 -0700 Subject: [PATCH 4/4] Fix baselines. --- .../Semantics/InheritanceBindingTests.cs | 25 +++++++++---------- .../Semantics/NullableReferenceTypesTests.cs | 12 ++++----- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs index 4f6e9c41c7410..8328ac79971c6 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs @@ -9022,9 +9022,9 @@ public override void Goo(T value) where T : struct, class { } // (8,26): error CS0115: 'Derived.Goo(T)': no suitable method found to override // 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 CS8869: The 'class' constraint cannot be combined with the 'struct' constraint + // (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_TypeConstraintsMustBeUniqueAndFirst).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 CS8869: The 'struct' constraint cannot be combined with the 'class' constraint + // (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_TypeConstraintsMustBeUniqueAndFirst).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 CS8869: The 'class' constraint cannot be combined with the 'struct' constraint + // (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_TypeConstraintsMustBeUniqueAndFirst).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 CS8869: The 'class' constraint cannot be combined with the 'struct' constraint + // (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_TypeConstraintsMustBeUniqueAndFirst).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 CS8869: The 'struct' constraint cannot be combined with the 'class' constraint + // (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_TypeConstraintsMustBeUniqueAndFirst).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 CS8869: The 'class' constraint cannot be combined with the 'struct' constraint + // (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_TypeConstraintsMustBeUniqueAndFirst).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 c0ba167fed8c4..8455d11226e6b 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -81660,10 +81660,10 @@ public static void F2(T2? t2) where T2 : notnull, struct comp.VerifyDiagnostics( // (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_TypeConstraintsMustBeUniqueAndFirst).WithLocation(8, 59), + 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_TypeConstraintsMustBeUniqueAndFirst).WithLocation(4, 58) + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "notnull").WithLocation(4, 58) ); var m = comp.SourceModule; @@ -81704,10 +81704,10 @@ public static void F2(T2? t2) where T2 : notnull, class comp.VerifyDiagnostics( // (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_TypeConstraintsMustBeUniqueAndFirst).WithLocation(4, 57), + 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_TypeConstraintsMustBeUniqueAndFirst).WithLocation(8, 59) + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(8, 59) ); var m = comp.SourceModule; @@ -81749,10 +81749,10 @@ public static void F2(T2? t2) where T2 : notnull, class? comp.VerifyDiagnostics( // (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_TypeConstraintsMustBeUniqueAndFirst).WithLocation(4, 58), + 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_TypeConstraintsMustBeUniqueAndFirst).WithLocation(8, 59) + Diagnostic(ErrorCode.ERR_TypeConstraintsMustBeUniqueAndFirst, "class").WithLocation(8, 59) ); var m = comp.SourceModule;