From 74b29425e7924266ae7ca76f4fa9c111a37367d0 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, 6 Jan 2019 11:07:07 +0100 Subject: [PATCH] fix #1407 --- TestSuite/CompilationSamples/delegates12.pas | 8 ++++++++ TreeConverter/NetWrappers/NetHelper.cs | 10 ++++++++++ TreeConverter/TreeRealization/generics.cs | 11 ++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 TestSuite/CompilationSamples/delegates12.pas diff --git a/TestSuite/CompilationSamples/delegates12.pas b/TestSuite/CompilationSamples/delegates12.pas new file mode 100644 index 000000000..9f798e721 --- /dev/null +++ b/TestSuite/CompilationSamples/delegates12.pas @@ -0,0 +1,8 @@ +function f(x: real) := x*2; + +function g(x: real) := x+1; + +begin + var fg: real -> real := f*g; + assert(abs(fg(1)-4) < 0.00000001); +end. \ No newline at end of file diff --git a/TreeConverter/NetWrappers/NetHelper.cs b/TreeConverter/NetWrappers/NetHelper.cs index 80c01e7dc..a40977fb9 100644 --- a/TreeConverter/NetWrappers/NetHelper.cs +++ b/TreeConverter/NetWrappers/NetHelper.cs @@ -515,6 +515,16 @@ namespace PascalABCCompiler.NetHelper mths = new List(); type_extensions.Add(tmp, mths); } + if ((tmp.BaseType == DelegateType || tmp.BaseType == MulticastDelegateType)) + { + List mths3 = null; + if (!type_extensions.TryGetValue(DelegateType, out mths3)) + { + mths3 = new List(); + type_extensions.Add(DelegateType, mths3); + } + mths3.Add(mi); + } mths.Add(mi); if (tmp.IsArray && !generic_array_type_extensions.TryGetValue(tmp.GetArrayRank(), out mths2)) { diff --git a/TreeConverter/TreeRealization/generics.cs b/TreeConverter/TreeRealization/generics.cs index b3f9e2457..3b4c01113 100644 --- a/TreeConverter/TreeRealization/generics.cs +++ b/TreeConverter/TreeRealization/generics.cs @@ -1137,9 +1137,18 @@ namespace PascalABCCompiler.TreeRealization { delegate_internal_interface dii = formal_type.get_internal_interface(internal_interface_kind.delegate_interface) as delegate_internal_interface; delegated_methods dm = fact_type as delegated_methods; + function_node fact_func = null; if (dm != null && dm.proper_methods.Count == 1) + fact_func = dm.proper_methods[0].simple_function_node; + else if (fact_type.IsDelegate) + { + var sil = fact_type.find_in_type("Invoke"); + if (sil != null && sil.Count > 0) + fact_func = sil[0].sym_info as function_node; + } + + if (fact_func != null) { - function_node fact_func = dm.proper_methods[0].simple_function_node; if (fact_func.parameters.Count != dii.parameters.Count) { goto eq_cmp;