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;