Open iskiselev opened 10 years ago
Looks like my implementation is not full enough. Here is once more problem test case:
.assembly TestAssembly {}
.assembly extern mscorlib {}
.class public abstract sealed Program
{
.method static void Main()
{
.maxstack 1
.entrypoint
.locals init (
[0] object,
[1] valuetype T
)
ldloca.s 1
initobj T
ldloc.1
box T
stloc.0
ldloc.0
unbox T
call instance void T::Increment()
ldloc.0
call void [mscorlib]System.Console::WriteLine(object)
ret
}
}
.class value public sequential sealed T
{
.field public int32 Value
.method public hidebysig virtual instance string ToString()
{
.maxstack 1
ldarg.0
ldflda int32 T::Value
call instance string [mscorlib]System.Int32::ToString()
ret
}
.method public hidebysig instance void Increment() cil managed
{
.maxstack 8
ldarg.0
dup
ldfld int32 T::Value
ldc.i4.1
add.ovf
stfld int32 T::Value
ret
}
}
Just for reference, here is sample on C++/CLI that is similar to Unbox_Issue569.il from #570:
using namespace System;
value class T{
public:
Int32 Value;
void Increment()
{
Value++;
}
virtual String^ ToString() override
{
return Value.ToString();
}
};
ref class TestClass
{
static int main()
{
Object ^object = gcnew T;
reinterpret_cast<T^>(object)->Increment();
Console::WriteLine(object);
return 0;
}
};
But I'm afraid that C++/CLI CodeProvider with Compiler will be much harder to implement then CILCodeProvider (Microsoft CppCodeProvider doesn't implement CodeCompiler)
Probably okay to have binary test cases for those. Honestly I don't give a shit about C++/CLI etc since it isn't portable to begin with, but maybe it's worthwhile to try and support it anyway.
It is not possible to do in C#, but it can be easy achieved with IL. Look on this C# pseudo code:
So, last method in listing is impossible in real C#. But it is possible with IL:
Expected result: 1 1
Translation of
DoRefWork
:Here is full IL listing: