Skip to content

CastCache caches wrong values for IDynamicInterfaceCastable #108229

Closed
@MichalStrehovsky

Description

@MichalStrehovsky

This should print true/true and it does so with CoreCLR or Native AOT in .NET 7. Starting with native AOT .NET 8, it prints true/false because CastCache cached the wrong answer. Likely regressed in #90234. Cc @VSadov

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

object o = new Shapeshifter();

Console.WriteLine(Is(o));
Console.WriteLine(Cast(o) != null);

[MethodImpl(MethodImplOptions.NoInlining)]
static bool Is(object o) => o is IEnumerable<object>;
[MethodImpl(MethodImplOptions.NoInlining)]
static IEnumerable<object> Cast(object o) => o as IEnumerable<object>;

class Shapeshifter : IDynamicInterfaceCastable
{
    public RuntimeTypeHandle GetInterfaceImplementation(RuntimeTypeHandle interfaceType) => throw new NotImplementedException();
    public bool IsInterfaceImplemented(RuntimeTypeHandle interfaceType, bool throwIfNotImplemented) => true;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions