From 477b2ba180fe1150516dc4e89fcf8f4674d8203f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D0=BD=D0=B4=D0=B0=D1=80=D0=B5=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD?= Date: Sun, 19 Aug 2018 19:29:35 +0200 Subject: [PATCH] bug fix #1041 --- NETGenerator/NETGenerator.cs | 3 +- TestSuite/CompilationSamples/PABCSystem.pas | 6 ++-- TestSuite/records12.pas | 23 +++++++++++++++ .../convertion_data_and_alghoritms.cs | 29 +++++++++++++++---- 4 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 TestSuite/records12.pas diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 4f7621ba0..5d7215d7d 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -7369,7 +7369,8 @@ namespace PascalABCCompiler.NETGenerator box_awaited = true; use_stn4 = true; } - + //if (ctn4 != null && ctn4.is_value_type && (ctn4 is ICommonTypeNode || ctn4 is ICompiledTypeNode && !TypeFactory.IsStandType((ctn4 as ICompiledTypeNode).compiled_type)) && ctn3 is ICompiledTypeNode && (ctn3 as ICompiledTypeNode).compiled_type != TypeFactory.ObjectType) + // box_awaited = false; if (!(real_parameters[i] is INullConstantNode)) { ti = helper.GetTypeReference(ctn); diff --git a/TestSuite/CompilationSamples/PABCSystem.pas b/TestSuite/CompilationSamples/PABCSystem.pas index 5e9d6ad19..2176c301e 100644 --- a/TestSuite/CompilationSamples/PABCSystem.pas +++ b/TestSuite/CompilationSamples/PABCSystem.pas @@ -6297,7 +6297,7 @@ begin elem := Activator.CreateInstance(t); fa := t.GetFields; for var i := 0 to fa.Length - 1 do - if not fa[i].IsStatic then + if not fa[i].IsStatic and not fa[i].IsLiteral then fa[i].SetValue(elem, AbstractBinaryFileReadT(f, fa[i].FieldType, ind, in_arr)); Result := elem; end @@ -6390,7 +6390,7 @@ begin fa := t.GetFields; for var i := 0 to fa.Length - 1 do begin - if not fa[i].IsStatic then + if not fa[i].IsStatic and not fa[i].IsLiteral then Write(f, fa[i].GetValue(val), true, ind, in_arr); end; end @@ -10820,7 +10820,7 @@ begin fa := t.GetFields; Result := 0; for var i := 0 to fa.Length - 1 do - if not fa[i].IsStatic then + if not fa[i].IsStatic and not fa[i].IsLiteral then Result := Result + RunTimeSizeOf(fa[i].FieldType) end else if t = typeof(string) then diff --git a/TestSuite/records12.pas b/TestSuite/records12.pas new file mode 100644 index 000000000..94b0a11ea --- /dev/null +++ b/TestSuite/records12.pas @@ -0,0 +1,23 @@ +type + r1=record + x,y:integer; + class function operator implicit(a:r1):string := a.x.ToString + a.y.ToString; + end; + +procedure test(o: object); +begin + assert(string(o) = '57'); +end; + +procedure test2(o: object); +begin + assert(string(r1(o)) = '57'); +end; + +begin + var a:r1; + (a.x,a.y) := (5,7); + test(string(a)); + test2(a); + test2(object(a)); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs b/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs index be3a9dc41..d0cc8e212 100644 --- a/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs +++ b/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs @@ -677,7 +677,8 @@ namespace PascalABCCompiler.TreeConverter if ((ret is base_function_call)) (ret as base_function_call).IsExplicitConversion = true; ret.type = to; - ret.conversion_type = conv_type; + if (ptc.first.convertion_method is basic_function_node) + ret.conversion_type = conv_type; return ret; } @@ -2361,19 +2362,37 @@ namespace PascalABCCompiler.TreeConverter } } } - + else if (to_ii != null && from.semantic_node_type == semantic_node_type.delegated_method && (from as delegated_methods).proper_methods[0].ret_type is lambda_any_type_node) + { + delegate_internal_interface to_dii = (delegate_internal_interface)to_ii; + if (to_dii.invoke_method.return_value_type != null) + { + to = to_dii.invoke_method.return_value_type; + if (to == SystemLibrary.SystemLibrary.integer_type) + return 94; + else if (to == SystemLibrary.SystemLibrary.int64_type) + return 96; + else if (to == SystemLibrary.SystemLibrary.double_type) + return 98; + else + return 1000; + } + } type_compare tc = type_table.compare_types(from, to); if (tc == type_compare.non_comparable_type) return 1000; if (!from.IsInterface && to.IsInterface) - return 2; + return 200; if (tc == type_compare.less_type) - return 1; + { + return 100; + } if (tc == type_compare.greater_type) - return 3; + return 300; return 1000; } + private function_node is_exist_eq_return_value_method(function_node fn, function_node_list funcs) { fn = find_eq_return_value_method_in_list(fn, funcs);