Skip to content

Commit

Permalink
Allow downcasting from derived to base for valuetypes
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Sep 27, 2015
1 parent cef6e29 commit 421c0be
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -100,7 +100,7 @@ public static bool IsBaseClass(TypeSymbol derivedType, TypeSymbol baseType, ref
Debug.Assert((object)baseType != null);

// A base class has got to be a class. The derived type might be a struct, enum, or delegate.
if (!baseType.IsClassType())
if (!baseType.IsClassType() && !(derivedType.IsValueType && baseType.IsValueType))
{
return false;
}
Expand Down Expand Up @@ -1754,6 +1754,13 @@ private bool HasExplicitReferenceConversion(TypeSymbol source, TypeSymbol destin
return true;
}

// Allow convert for valuetype
if (source.IsValueType && destination.IsValueType &&
IsBaseClass(source, destination, ref useSiteDiagnostics))
{
return true;
}

return false;
}

Expand Down

0 comments on commit 421c0be

Please sign in to comment.