Skip to content
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

CastCache caches wrong values for IDynamicInterfaceCastable #108229

Closed
MichalStrehovsky opened this issue Sep 25, 2024 · 1 comment · Fixed by #108328
Closed

CastCache caches wrong values for IDynamicInterfaceCastable #108229

MichalStrehovsky opened this issue Sep 25, 2024 · 1 comment · Fixed by #108328
Labels
area-NativeAOT-coreclr in-pr There is an active PR which will close this issue when it is merged regression-from-last-release

Comments

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Sep 25, 2024

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;
}
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this issue Sep 27, 2024
Fixes dotnet#108229.

The actual fix is the addition of an `if` check where it originally wasn't. I also fixed the other checks for consistency - positive checks are fine to cache, and negative checks against non-interface targets are also fine to cache.
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Sep 27, 2024
jkotas pushed a commit that referenced this issue Sep 28, 2024
Fixes #108229.

The actual fix is the addition of an `if` check where it originally wasn't. I also fixed the other checks for consistency - positive checks are fine to cache, and negative checks against non-interface targets are also fine to cache.
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Sep 28, 2024
sirntar pushed a commit to sirntar/runtime that referenced this issue Sep 30, 2024
Fixes dotnet#108229.

The actual fix is the addition of an `if` check where it originally wasn't. I also fixed the other checks for consistency - positive checks are fine to cache, and negative checks against non-interface targets are also fine to cache.
@github-actions github-actions bot locked and limited conversation to collaborators Oct 29, 2024
github-actions bot pushed a commit that referenced this issue Nov 20, 2024
Fixes #108229.

The actual fix is the addition of an `if` check where it originally wasn't. I also fixed the other checks for consistency - positive checks are fine to cache, and negative checks against non-interface targets are also fine to cache.
mikelle-rogers pushed a commit to mikelle-rogers/runtime that referenced this issue Dec 10, 2024
Fixes dotnet#108229.

The actual fix is the addition of an `if` check where it originally wasn't. I also fixed the other checks for consistency - positive checks are fine to cache, and negative checks against non-interface targets are also fine to cache.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-NativeAOT-coreclr in-pr There is an active PR which will close this issue when it is merged regression-from-last-release
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant