diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs
index 10d5b6ea9f9fe..4bbac7ae4e8c5 100644
--- a/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs
+++ b/src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs
@@ -171,12 +171,17 @@ private TypeParameterConstraintClause BindTypeParameterConstraints(
if ((constraints & (TypeParameterConstraintKind.ReferenceType | TypeParameterConstraintKind.ValueType)) != 0)
{
- // System.Enum is allowed to exist with class and struct constraints
- if (type.SpecialType != SpecialType.System_Enum)
+ switch (type.SpecialType)
{
- // "'{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint"
- Error(diagnostics, ErrorCode.ERR_RefValBoundWithClass, syntax, type);
- continue;
+ case SpecialType.System_Enum:
+ case SpecialType.System_Delegate:
+ case SpecialType.System_MulticastDelegate:
+ break;
+
+ default:
+ // "'{0}': cannot specify both a constraint class and the 'class' or 'struct' constraint"
+ Error(diagnostics, ErrorCode.ERR_RefValBoundWithClass, syntax, type);
+ continue;
}
}
}
@@ -204,10 +209,13 @@ private static bool IsValidConstraintType(TypeConstraintSyntax syntax, TypeSymbo
CheckFeatureAvailability(syntax, MessageID.IDS_FeatureEnumGenericTypeConstraint, diagnostics);
break;
- case SpecialType.System_Object:
- case SpecialType.System_ValueType:
case SpecialType.System_Delegate:
case SpecialType.System_MulticastDelegate:
+ CheckFeatureAvailability(syntax, MessageID.IDS_FeatureDelegateGenericTypeConstraint, diagnostics);
+ break;
+
+ case SpecialType.System_Object:
+ case SpecialType.System_ValueType:
case SpecialType.System_Array:
// "Constraint cannot be special class '{0}'"
Error(diagnostics, ErrorCode.ERR_SpecialTypeAsBound, syntax, type);
diff --git a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
index 6f94d1648ae1b..4d86431e090cf 100644
--- a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
+++ b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs
@@ -10349,6 +10349,15 @@ internal static string IDS_FeatureDefaultLiteral {
}
}
+ ///
+ /// Looks up a localized string similar to delegate generic type constraints.
+ ///
+ internal static string IDS_FeatureDelegateGenericTypeConstraint {
+ get {
+ return ResourceManager.GetString("IDS_FeatureDelegateGenericTypeConstraint", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to dictionary initializer.
///
diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx
index 5ee80ff140222..d1247c0c7e0f4 100644
--- a/src/Compilers/CSharp/Portable/CSharpResources.resx
+++ b/src/Compilers/CSharp/Portable/CSharpResources.resx
@@ -5249,4 +5249,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
enum generic type constraints
+
+ delegate generic type constraints
+
\ No newline at end of file
diff --git a/src/Compilers/CSharp/Portable/Errors/MessageID.cs b/src/Compilers/CSharp/Portable/Errors/MessageID.cs
index 5bcb553d4dfb8..e1b371cf53552 100644
--- a/src/Compilers/CSharp/Portable/Errors/MessageID.cs
+++ b/src/Compilers/CSharp/Portable/Errors/MessageID.cs
@@ -148,6 +148,7 @@ internal enum MessageID
IDS_FeatureAttributesOnBackingFields = MessageBase + 12731,
IDS_FeatureEnumGenericTypeConstraint = MessageBase + 12732,
+ IDS_FeatureDelegateGenericTypeConstraint = MessageBase + 12733,
}
// Message IDs may refer to strings that need to be localized.
@@ -190,6 +191,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)
// C# 7.3 features.
case MessageID.IDS_FeatureAttributesOnBackingFields: // semantic check
case MessageID.IDS_FeatureEnumGenericTypeConstraint: // semantic check
+ case MessageID.IDS_FeatureDelegateGenericTypeConstraint: // semantic check
return LanguageVersion.CSharp7_3;
// C# 7.2 features.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
index db4f65137ba32..bf4dc1302ae70 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
@@ -8605,6 +8605,11 @@ Pokud chcete odstranit toto varování, můžete místo toho použít /reference
enum generic type constraints
+
+
+ delegate generic type constraints
+
+