Skip to content

Commit

Permalink
[mono] Use correct cast_class for IntPtr[] (#103841)
Browse files Browse the repository at this point in the history
This change fixes the behavior to be like modern .NET instead of .NET Framework.

Fixes #97145
  • Loading branch information
steveisok committed Jun 26, 2024
1 parent b8f28c7 commit 5a0eb6e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/mono/mono/metadata/class-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,18 +1039,14 @@ class_composite_fixup_cast_class (MonoClass *klass, gboolean for_ptr)
case MONO_TYPE_U2:
klass->cast_class = mono_defaults.int16_class;
break;
case MONO_TYPE_U4:
#if TARGET_SIZEOF_VOID_P == 4
case MONO_TYPE_I:
case MONO_TYPE_U:
#endif
klass->cast_class = mono_defaults.int_class;
break;
case MONO_TYPE_U4:
klass->cast_class = mono_defaults.int32_class;
break;
case MONO_TYPE_U8:
#if TARGET_SIZEOF_VOID_P == 8
case MONO_TYPE_I:
case MONO_TYPE_U:
#endif
klass->cast_class = mono_defaults.int64_class;
break;
default:
Expand Down
20 changes: 20 additions & 0 deletions src/tests/Loader/classloader/Casting/Normalization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;

using Xunit;

public class NormalizationTests
{
[Fact]
public static void IntPtrArrayNormalization()
{
object x0 = new long[1];
object x1 = new ulong[1];

Assert.False(x0 is IntPtr[]);
Assert.False(x1 is IntPtr[]);
}
}
5 changes: 5 additions & 0 deletions src/tests/Loader/classloader/Casting/Normalization.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<Compile Include="Normalization.cs" />
</ItemGroup>
</Project>

0 comments on commit 5a0eb6e

Please sign in to comment.