-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Managed type system casting logic doesn't handle all array variance #85146
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsCompile following with optimizations on: class Program
{
static void Main()
{
object source = new Enum0[] { Enum0.First, Enum0.Second, Enum0.Third };
Console.WriteLine(source is IEnumerable<Enum1>);
}
enum Enum0 { First, Second, Third }
enum Enum1 { }
} Expected: prints true This is because the CanCastTo logic within the managed type system doesn't think these are castable. RyuJIT hardcodes this to false in codegen.
|
Just a thing to clarify: The |
It returns true if a cast can succeed. You can do |
That's good to know, thank you. I always expected it to only return true on exact type matches for types you defined. |
Compile following with optimizations on:
Expected: prints true
Observed: prints false
This is because the CanCastTo logic within the managed type system doesn't think these are castable. RyuJIT hardcodes this to false in codegen.
The text was updated successfully, but these errors were encountered: