From 69dbce91d71d280cf6fbc3c5cdd066293542afd3 Mon Sep 17 00:00:00 2001 From: VladV <vanifatov.vlad@yandex.ru> Date: Tue, 10 Jan 2023 10:55:16 +0400 Subject: [PATCH] Fix IL code for virtual call --- CodeGen/AtomWeaverV2.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CodeGen/AtomWeaverV2.cs b/CodeGen/AtomWeaverV2.cs index 558f143..5f97d2b 100644 --- a/CodeGen/AtomWeaverV2.cs +++ b/CodeGen/AtomWeaverV2.cs @@ -271,7 +271,17 @@ private void Prepend(ref int ind, IList<Instruction> il) ? Instruction.Create(OpCodes.Ldstr, _atomDebugName) : Instruction.Create(OpCodes.Ldnull)); // debugName il.Insert(ind++, Instruction.Create(OpCodes.Ldarg_0)); // getter_method - il.Insert(ind++, Instruction.Create(OpCodes.Ldftn, _property.GetMethod)); + + if (_property.GetMethod.IsVirtual) + { + il.Insert(ind++, Instruction.Create(OpCodes.Dup)); + il.Insert(ind++, Instruction.Create(OpCodes.Ldvirtftn, _property.GetMethod)); + } + else + { + il.Insert(ind++, Instruction.Create(OpCodes.Ldftn, _property.GetMethod)); + } + il.Insert(ind++, Instruction.Create(OpCodes.Newobj, _atomPullCtorMethod)); il.Insert(ind++, Instruction.Create(_options.KeepAlive ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0)); il.Insert(ind++, Instruction.Create(OpCodes.Call, _atomCreateMethod)); // create atom