Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Delegate and MulticastDelegate as generic type constraints #24443

Merged
merged 2 commits into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions src/Compilers/CSharp/Portable/Binder/Binder_Constraints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -5249,4 +5249,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="IDS_FeatureEnumGenericTypeConstraint" xml:space="preserve">
<value>enum generic type constraints</value>
</data>
<data name="IDS_FeatureDelegateGenericTypeConstraint" xml:space="preserve">
<value>delegate generic type constraints</value>
</data>
</root>
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ Pokud chcete odstranit toto varování, můžete místo toho použít /reference
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ Um die Warnung zu beheben, können Sie stattdessen /reference verwenden (Einbett
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ Para eliminar la advertencia puede usar /reference (establezca la propiedad Embe
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ Pour supprimer l'avertissement, vous pouvez utiliser la commande /reference (dé
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ Per rimuovere l'avviso, è invece possibile usare /reference (impostare la propr
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ Aby usunąć ostrzeżenie, możesz zamiast tego użyć opcji /reference (ustaw w
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ Para incorporar informações de tipo de interoperabilidade para os dois assembl
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ Uyarıyı kaldırmak için, /reference kullanabilirsiniz (Birlikte Çalışma T
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8605,6 +8605,11 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<target state="new">enum generic type constraints</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureDelegateGenericTypeConstraint">
<source>delegate generic type constraints</source>
<target state="new">delegate generic type constraints</target>
<note />
</trans-unit>
</body>
</file>
</xliff>
Loading