From 66b5221d1eb5d9f344d8ea013739ba45ea6cb80e Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Mon, 24 Jun 2019 15:12:52 +0300 Subject: [PATCH] fix #1956 --- TestSuite/errors/err0323.pas | 22 +++++++++++++++++++ .../convertion_data_and_alghoritms.cs | 8 ++++++- bin/Lng/Eng/SemanticErrors_ms.dat | 3 ++- bin/Lng/Rus/SemanticErrors_ms.dat | 3 ++- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 TestSuite/errors/err0323.pas diff --git a/TestSuite/errors/err0323.pas b/TestSuite/errors/err0323.pas new file mode 100644 index 000000000..64a7b2ae1 --- /dev/null +++ b/TestSuite/errors/err0323.pas @@ -0,0 +1,22 @@ +type + t1 = class + constructor Create(i: integer); + begin + //Create(); + end; + + constructor Create(f: ()->byte); + begin + end; + + constructor Create(); + begin + //var a := 1; + Create(()->1); + end; + end; + +begin + {var p := new t1; + p.Create(()->1);} +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 39c1aee94..06410c63d 100644 --- a/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs +++ b/TreeConverter/TreeConversion/convertion_data_and_alghoritms.cs @@ -448,7 +448,13 @@ namespace PascalABCCompiler.TreeConverter if (syntax_tree_visitor.inherited_ident_processing) syntax_tree_visitor.AddError(new SimpleSemanticError(loc, "INHERITED_CONSTRUCTOR_CALL_MUST_BE_FIRST")); else - syntax_tree_visitor.AddError(new SimpleSemanticError(loc, "CAN_NOT_CALL_CONSTRUCTOR_AS_PROCEDURE")); + { + var lambdasInParameters = syntax_nodes_parameters?.Any(ex => ex is SyntaxTree.function_lambda_definition) ?? false; + if (lambdasInParameters) + syntax_tree_visitor.AddError(new SimpleSemanticError(loc, "LAMBDAS_IN_CONSTRUCTOR_PARAMETERS_ARE_FORBIDDEN_IN_THIS_CONTEXT")); + else syntax_tree_visitor.AddError(new SimpleSemanticError(loc, "CAN_NOT_CALL_CONSTRUCTOR_AS_PROCEDURE")); + } + } cmc = ccc; } diff --git a/bin/Lng/Eng/SemanticErrors_ms.dat b/bin/Lng/Eng/SemanticErrors_ms.dat index cbaec5c70..44cb28a16 100644 --- a/bin/Lng/Eng/SemanticErrors_ms.dat +++ b/bin/Lng/Eng/SemanticErrors_ms.dat @@ -26,4 +26,5 @@ UNNAMED_RECORD_CANNOT_CONTAIN_METHODS=Unnamed records can not contain methods UNNAMED_RECORD_CANNOT_CONTAIN_CONSTRUCTORS=Unnamed records can not contain constructors UNNAMED_RECORD_CAN_CONTAIN_ONLY_ONE_PUBLIC_VISIBILITY_SECTION=Unnamed records can contain only one section with public visibility UNNAMED_RECORD_CANNOT_CONTAIN_SEVERAL_VISIBILITY_SECTIONS=Unnamed records can not contain several visibility section -OPENMP_CONTROLLED_CONSTRUCTIONS_CANNOT_CONTAIN_LAMBDAS=OpenMP-directive-based constructions cannot contain lambdas \ No newline at end of file +OPENMP_CONTROLLED_CONSTRUCTIONS_CANNOT_CONTAIN_LAMBDAS=OpenMP-directive-based constructions cannot contain lambdas +LAMBDAS_IN_CONSTRUCTOR_PARAMETERS_ARE_FORBIDDEN_IN_THIS_CONTEXT=Lambda-expressions as constructor parameters are forbidden in this context \ No newline at end of file diff --git a/bin/Lng/Rus/SemanticErrors_ms.dat b/bin/Lng/Rus/SemanticErrors_ms.dat index 751440b0a..14af8850f 100644 --- a/bin/Lng/Rus/SemanticErrors_ms.dat +++ b/bin/Lng/Rus/SemanticErrors_ms.dat @@ -27,4 +27,5 @@ UNNAMED_RECORD_CANNOT_CONTAIN_METHODS=Безымянные записи не м UNNAMED_RECORD_CANNOT_CONTAIN_CONSTRUCTORS=Безымянные записи не могут содержать конструкторы UNNAMED_RECORD_CAN_CONTAIN_ONLY_ONE_PUBLIC_VISIBILITY_SECTION=Безымянные записи могут содержать лишь одну секцию с public-видимостью UNNAMED_RECORD_CANNOT_CONTAIN_SEVERAL_VISIBILITY_SECTIONS=Безымянные записи не могут содержать несколько секций видимости -OPENMP_CONTROLLED_CONSTRUCTIONS_CANNOT_CONTAIN_LAMBDAS=Лямбда-выражения не могут содержаться внутри конструкций под управлением OpenMP-директив \ No newline at end of file +OPENMP_CONTROLLED_CONSTRUCTIONS_CANNOT_CONTAIN_LAMBDAS=Лямбда-выражения не могут содержаться внутри конструкций под управлением OpenMP-директив +LAMBDAS_IN_CONSTRUCTOR_PARAMETERS_ARE_FORBIDDEN_IN_THIS_CONTEXT=Лямбда-выражения как параметры конструктора запрещены в этом контексте \ No newline at end of file