Skip to content
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
2 changes: 2 additions & 0 deletions docs/coding-guidelines/breaking-change-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ Breaking Change Rules

* Changing a `struct` type to a `ref struct` type and vice versa

* Changing a `struct` type to an `enum` type and vice versa

* Changing the underlying type of an enum

This is a compile-time and behavioral breaking change as well as a binary breaking change which can make attribute arguments unparsable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public static class CastFolding
[MethodImpl(MethodImplOptions.NoInlining)]
public static bool StructIsOtherStruct(SourceStruct s) => (object)s is TargetStruct;

[MethodImpl(MethodImplOptions.NoInlining)]
public static bool StructIsEnum(SourceStruct s) => (object)s is Enum;

[MethodImpl(MethodImplOptions.NoInlining)]
public static bool StructIsInterface(ControlStruct s) => (object)s is INotImplemented;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ void Validate(ReadyToRunReader reader)
Assert.False(importedTypes.Contains("byte"), diagnostic);
Assert.False(importedTypes.Contains("SourceStruct"), diagnostic);
Assert.False(importedTypes.Contains("TargetStruct"), diagnostic);
Assert.False(importedTypes.Contains("System.Enum"), diagnostic);

// Casts to interfaces fold only when every type in the hierarchy is in the version bubble,
// which includes System.Object and System.ValueType only with the framework in the bubble.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3972,8 +3972,8 @@ private bool IsNegativeCastResultVersionResilient(TypeDesc fromType, TypeDesc to
if (fromType.HasTypeEquivalence || toType.HasTypeEquivalence)
return false;

// A value type can gain interfaces (or become an enum), but its other cast targets are fixed.
if (fromType.IsValueType && !toType.IsInterface && !toType.IsWellKnownType(WellKnownType.Enum))
// A value type can gain interfaces, but its other cast targets are fixed.
if (fromType.IsValueType && !toType.IsInterface)
return true;

// Otherwise every type that decides the cast must version with this code. Array and variant casts
Expand Down
Loading