diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 9e7d75032..bcc565c13 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -127,6 +127,7 @@ namespace PascalABCCompiler.NETGenerator protected CompilerOptions comp_opt = new CompilerOptions();//опции компилятора protected Dictionary sym_docs = new Dictionary();//таблица отладочных документов protected bool is_constructor = false;//флаг, переводим ли мы конструктор + protected bool init_call_awaited = false; protected bool save_debug_info = false; protected bool add_special_debug_variables = false; protected bool make_next_spoint = true; @@ -5782,15 +5783,17 @@ namespace PascalABCCompiler.NETGenerator ConvertCommonFunctionConstantDefinitions(value.constants); ConvertLocalVariables(value.var_definition_nodes); //вызываем метод $Init$ для инициализации массивов и проч. - if (value.polymorphic_state != polymorphic_state.ps_static && value.common_comprehensive_type.base_type is ICompiledTypeNode && (value.common_comprehensive_type.base_type as ICompiledTypeNode).compiled_type == TypeFactory.ObjectType) + /*if (value.polymorphic_state != polymorphic_state.ps_static && value.common_comprehensive_type.base_type is ICompiledTypeNode && (value.common_comprehensive_type.base_type as ICompiledTypeNode).compiled_type == TypeFactory.ObjectType) { il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Call, TypeFactory.ObjectType.GetConstructor(Type.EmptyTypes)); - } + }*/ if (value.polymorphic_state != polymorphic_state.ps_static) { - il.Emit(OpCodes.Ldarg_0); - il.Emit(OpCodes.Call, cur_ti.init_meth); + init_call_awaited = true; + + //il.Emit(OpCodes.Ldarg_0); + //il.Emit(OpCodes.Call, cur_ti.init_meth); } //переводим тело is_constructor = true; @@ -9182,6 +9185,12 @@ namespace PascalABCCompiler.NETGenerator { is_dot_expr = false; } + if (init_call_awaited && !value.new_obj_awaited()) + { + il.Emit(OpCodes.Ldarg_0); + il.Emit(OpCodes.Call, cur_ti.init_meth); + init_call_awaited = false; + } } //вызов откомпилированного конструктора @@ -9263,7 +9272,13 @@ namespace PascalABCCompiler.NETGenerator { is_dot_expr = false; } - //\ssyy + //\ssyy + if (init_call_awaited && !value.new_obj_awaited()) + { + il.Emit(OpCodes.Ldarg_0); + il.Emit(OpCodes.Call, cur_ti.init_meth); + init_call_awaited = false; + } } private bool TypeNeedToFix(ITypeNode type) diff --git a/TestSuite/extensionmethods19.pas b/TestSuite/extensionmethods19.pas new file mode 100644 index 000000000..dbef8b67e --- /dev/null +++ b/TestSuite/extensionmethods19.pas @@ -0,0 +1,5 @@ +begin + var a := Arr(1,3,5,4,3); + var b := a.Println.ToArray; + assert(b[2] = 5); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 5d85ce8eb..9e7da312d 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -8975,6 +8975,30 @@ namespace PascalABCCompiler.TreeConverter { return new indefinite_reference(dn as indefinite_definition_node, get_location(id_right)); } + if (expected_delegate && en != null) + { + SymbolInfo tmp_si = si; + function_node tmp_fn = null; + bool has_empty_methods = false; + bool only_extension_methods = true; + while (tmp_si != null) + { + tmp_fn = tmp_si.sym_info as function_node; + if (tmp_fn != null) + { + if (!tmp_fn.is_extension_method) + only_extension_methods = false; + else + { + if (tmp_fn.parameters.Count == 1 || tmp_fn.parameters.Count == 2 && (tmp_fn.parameters[1].is_params || tmp_fn.parameters[1].default_value != null)) + has_empty_methods = true; + } + } + tmp_si = tmp_si.Next; + } + if (has_empty_methods && only_extension_methods) + expected_delegate = false; + } if (expected_delegate) return make_delegate_wrapper(en, si, get_location(id_right), false); else