diff --git a/src/Neo.Compiler.CSharp/MethodConvert/Helpers/CallHelpers.cs b/src/Neo.Compiler.CSharp/MethodConvert/Helpers/CallHelpers.cs index b6ff59b48..005c91b0a 100644 --- a/src/Neo.Compiler.CSharp/MethodConvert/Helpers/CallHelpers.cs +++ b/src/Neo.Compiler.CSharp/MethodConvert/Helpers/CallHelpers.cs @@ -73,6 +73,15 @@ private void CallInstanceMethod(SemanticModel model, IMethodSymbol symbol, bool var (convert, methodCallingConvention) = GetMethodConvertAndCallingConvention(model, symbol); + if (NeedInstanceConstructor(symbol) && convert != null && convert.Instructions.Count >= 2) + { + Instruction initslot = convert.Instructions[0]; + Instruction ret = convert.Instructions[1]; + if (initslot.OpCode == OpCode.INITSLOT && initslot.Operand?[0] == 0 && initslot.Operand[1] == 1 + && ret.OpCode == OpCode.RET) + return; // Do not call meaningless contructors + } + HandleConstructorDuplication(instanceOnStack, methodCallingConvention, symbol); PrepareArgumentsForMethod(model, symbol, arguments, methodCallingConvention); @@ -98,6 +107,15 @@ private void CallMethodWithInstanceExpression(SemanticModel model, IMethodSymbol var (convert, methodCallingConvention) = GetMethodConvertAndCallingConvention(model, symbol, instanceExpression); + if (NeedInstanceConstructor(symbol) && convert != null && convert.Instructions.Count >= 2) + { + Instruction initslot = convert.Instructions[0]; + Instruction ret = convert.Instructions[1]; + if (initslot.OpCode == OpCode.INITSLOT && initslot.Operand?[0] == 0 && initslot.Operand[1] == 1 + && ret.OpCode == OpCode.RET) + return; // Do not call meaningless contructors + } + HandleInstanceExpression(model, symbol, instanceExpression, methodCallingConvention, beforeArguments: true); PrepareArgumentsForMethod(model, symbol, arguments, methodCallingConvention);