diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 87c79aee4..c8b923223 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -1435,6 +1435,41 @@ namespace PascalABCCompiler.NETGenerator } } + else + { + bool has_meth_contrains = false; + foreach (var meth in ctn.methods) + { + + if (meth.generic_params != null && meth.generic_params.Count > 0) + foreach (var gp in meth.generic_params) + { + if (!(gp.base_type is ICommonTypeNode)) + continue; + TypeBuilder tb = helper.GetTypeReference(gp.base_type).tp as TypeBuilder; + if (tb != null && !closed_types.Contains(tb)) + { + try + { + tb.CreateType(); + closed_types.Add(tb); + has_meth_contrains = true; + } + catch (TypeLoadException ex2) + { + throw new PascalABCCompiler.Errors.CommonCompilerError(ex.Message, ctn.Location.document.file_name, ctn.Location.begin_line_num, ctn.Location.begin_column_num); + } + } + } + } + if (has_meth_contrains) + continue; + else + { + failed_types.Add(value_types[i]); + continue; + } + } throw new PascalABCCompiler.Errors.CommonCompilerError(ex.Message, ctn.Location.document.file_name, ctn.Location.begin_line_num, ctn.Location.begin_column_num); } else diff --git a/TestSuite/genericrecords5.pas b/TestSuite/genericrecords5.pas new file mode 100644 index 000000000..7662d88b9 --- /dev/null +++ b/TestSuite/genericrecords5.pas @@ -0,0 +1,17 @@ +var i: integer; +type + Base = class end; + + r1 = record + procedure pr1(par1: T); where T: Base; + begin + i := 1; + end; + + end; + +begin + var r: r1; + r.pr1(new Base); + assert(i = 1); +end. \ No newline at end of file diff --git a/TestSuite/genericrecords6.pas b/TestSuite/genericrecords6.pas new file mode 100644 index 000000000..4f1d4717a --- /dev/null +++ b/TestSuite/genericrecords6.pas @@ -0,0 +1,17 @@ +var i: integer; +type + Base = class end; + Base2 = class end; + r1 = record + procedure pr1(par1: T; par2: T2); where T: Base; where T2: Base2; + begin + i := 1; + end; + + end; + +begin + var r: r1; + r.pr1(new Base, new Base2); + assert(i = 1); +end. \ No newline at end of file