-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
VB: Recognize and check an unmanaged
constraint
#75665
Changes from 1 commit
a55f298
4e488be
cbf6e39
c18e059
57147d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
|
||
namespace Microsoft.CodeAnalysis.Symbols | ||
{ | ||
|
@@ -16,5 +17,69 @@ internal interface INamedTypeSymbolInternal : ITypeSymbolInternal | |
|
||
ImmutableArray<ISymbolInternal> GetMembers(); | ||
ImmutableArray<ISymbolInternal> GetMembers(string name); | ||
|
||
/// <summary> | ||
/// True if this type or some containing type has type parameters. | ||
/// </summary> | ||
public bool IsGenericType { get; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
internal static class Helpers | ||
{ | ||
/// <summary> | ||
/// Returns True or False if we can determine whether the type is managed | ||
/// without looking at its fields and Unknown otherwise. | ||
/// Also returns whether or not the given type is generic. | ||
/// </summary> | ||
public static (ThreeState isManaged, bool hasGenerics) IsManagedTypeHelper(INamedTypeSymbolInternal type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I prefer to keep the code as is. I do not foresee us using this helper much in the future. Therefore, in my opinion there is no good reason to "pollute" name lookup binding space with it. If we could use Default Interface Implementations feature in our code, I would make this method a member of |
||
{ | ||
// To match dev10, we treat enums as their underlying types. | ||
if (type.TypeKind == TypeKind.Enum) | ||
{ | ||
Debug.Assert(type.EnumUnderlyingType is not null); | ||
type = type.EnumUnderlyingType; | ||
} | ||
|
||
// Short-circuit common cases. | ||
switch (type.SpecialType) | ||
{ | ||
case SpecialType.System_Void: | ||
case SpecialType.System_Boolean: | ||
case SpecialType.System_Char: | ||
case SpecialType.System_SByte: | ||
case SpecialType.System_Byte: | ||
case SpecialType.System_Int16: | ||
case SpecialType.System_UInt16: | ||
case SpecialType.System_Int32: | ||
case SpecialType.System_UInt32: | ||
case SpecialType.System_Int64: | ||
case SpecialType.System_UInt64: | ||
case SpecialType.System_Decimal: | ||
case SpecialType.System_Single: | ||
case SpecialType.System_Double: | ||
case SpecialType.System_IntPtr: | ||
case SpecialType.System_UIntPtr: | ||
case SpecialType.System_ArgIterator: | ||
case SpecialType.System_RuntimeArgumentHandle: | ||
return (ThreeState.False, false); | ||
case SpecialType.System_TypedReference: | ||
return (ThreeState.True, false); | ||
case SpecialType.None: | ||
default: | ||
// CONSIDER: could provide cases for other common special types. | ||
break; // Proceed with additional checks. | ||
} | ||
|
||
bool hasGenerics = type.IsGenericType; | ||
switch (type.TypeKind) | ||
{ | ||
case TypeKind.Enum: | ||
return (ThreeState.False, hasGenerics); | ||
case TypeKind.Struct: | ||
return (ThreeState.Unknown, hasGenerics); | ||
default: | ||
return (ThreeState.True, hasGenerics); | ||
} | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is repeated several times. Consider extracting a helper method. #Resolved