From 6191eb03104b4410c41db5e8a8724fe1d26c38fa Mon Sep 17 00:00:00 2001 From: Lucas Trzesniewski Date: Sat, 27 Jul 2024 20:39:50 +0200 Subject: [PATCH] Add more tests --- .../ReferencedAssemblyType.cs | 10 ++++++- .../FieldRefTestCases.cs | 27 +++++++++++++++++++ src/InlineIL.Tests/Weaving/FieldRefTests.cs | 14 ++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/InlineIL.Tests.Common/ReferencedAssemblyType.cs b/src/InlineIL.Tests.Common/ReferencedAssemblyType.cs index dc024fd..b58d8e7 100644 --- a/src/InlineIL.Tests.Common/ReferencedAssemblyType.cs +++ b/src/InlineIL.Tests.Common/ReferencedAssemblyType.cs @@ -1,8 +1,16 @@ namespace InlineIL.Tests.Common; -public class TypeFromReferencedAssembly +public unsafe class TypeFromReferencedAssembly { public readonly StructFromReferencedAssembly FieldWithTypeFromThisAssembly = default; + public readonly StructFromReferencedAssembly* PointerField = default; +} + +public unsafe class TypeFromReferencedAssembly + where T : unmanaged +{ + public readonly T* PointerField = default; } public struct StructFromReferencedAssembly; +public struct OtherStructFromReferencedAssembly; diff --git a/src/InlineIL.Tests.UnverifiableAssemblyToProcess/FieldRefTestCases.cs b/src/InlineIL.Tests.UnverifiableAssemblyToProcess/FieldRefTestCases.cs index a6b6434..84ae7ba 100644 --- a/src/InlineIL.Tests.UnverifiableAssemblyToProcess/FieldRefTestCases.cs +++ b/src/InlineIL.Tests.UnverifiableAssemblyToProcess/FieldRefTestCases.cs @@ -1,3 +1,4 @@ +using System; using System.Diagnostics.CodeAnalysis; using InlineIL.Tests.Common; using static InlineIL.IL.Emit; @@ -18,4 +19,30 @@ public void ReadFieldFromReferencedAssemblyType() Ldfld(FieldRef.Field(typeof(TypeFromReferencedAssembly), nameof(TypeFromReferencedAssembly.FieldWithTypeFromThisAssembly))); Pop(); } + + public void ReadPointerFieldFromReferencedAssemblyType() + { + IL.Push(new TypeFromReferencedAssembly()); + Ldfld(FieldRef.Field(typeof(TypeFromReferencedAssembly), nameof(TypeFromReferencedAssembly.PointerField))); + Pop(); + } + + public void ReadGenericPointerFieldFromReferencedAssemblyType() + { + IL.Push(new TypeFromReferencedAssembly()); + Ldfld(FieldRef.Field(typeof(TypeFromReferencedAssembly), nameof(TypeFromReferencedAssembly.PointerField))); + Pop(); + + IL.Push(new TypeFromReferencedAssembly()); + Ldfld(FieldRef.Field(typeof(TypeFromReferencedAssembly), nameof(TypeFromReferencedAssembly.PointerField))); + Pop(); + + IL.Push(new TypeFromReferencedAssembly()); + Ldfld(FieldRef.Field(typeof(TypeFromReferencedAssembly), nameof(TypeFromReferencedAssembly.PointerField))); + Pop(); + } +} + +internal struct InternalStruct +{ } diff --git a/src/InlineIL.Tests/Weaving/FieldRefTests.cs b/src/InlineIL.Tests/Weaving/FieldRefTests.cs index 28c1bdc..59ea7ec 100644 --- a/src/InlineIL.Tests/Weaving/FieldRefTests.cs +++ b/src/InlineIL.Tests/Weaving/FieldRefTests.cs @@ -24,6 +24,20 @@ public void should_handle_fields_with_types_from_referenced_assemblies() instance.ReadFieldFromReferencedAssemblyType(); } + [Fact] + public void should_handle_pointer_fields_with_types_from_referenced_assemblies() + { + var instance = GetUnverifiableInstance(); + instance.ReadPointerFieldFromReferencedAssemblyType(); + } + + [Fact] + public void should_handle_generic_fields_with_types_from_referenced_assemblies() + { + var instance = GetUnverifiableInstance(); + instance.ReadGenericPointerFieldFromReferencedAssemblyType(); + } + [Fact] public void should_reference_field_in_different_ways() {