diff --git a/TestSuite/errors/err0250.pas b/TestSuite/errors/err0250.pas new file mode 100644 index 000000000..5c1daae12 --- /dev/null +++ b/TestSuite/errors/err0250.pas @@ -0,0 +1,10 @@ +type + t1 = class + + constructor := exit; + + procedure p1(a: array of record end) := exit; + + end; + +begin end. \ No newline at end of file diff --git a/TestSuite/errors/err0251.pas b/TestSuite/errors/err0251.pas new file mode 100644 index 000000000..f23f210e2 --- /dev/null +++ b/TestSuite/errors/err0251.pas @@ -0,0 +1,10 @@ +type + t1 = class + + constructor := exit; + + procedure p1(a: set of record end) := exit; + + end; + +begin end. \ No newline at end of file diff --git a/TestSuite/errors/err0252.pas b/TestSuite/errors/err0252.pas new file mode 100644 index 000000000..459a7bdf4 --- /dev/null +++ b/TestSuite/errors/err0252.pas @@ -0,0 +1,10 @@ +type + t1 = class + + constructor := exit; + + procedure p1(a: file of record end) := exit; + + end; + +begin end. \ No newline at end of file diff --git a/TestSuite/errors/err0253.pas b/TestSuite/errors/err0253.pas new file mode 100644 index 000000000..749852f68 --- /dev/null +++ b/TestSuite/errors/err0253.pas @@ -0,0 +1,10 @@ +type + t1 = class + + constructor := exit; + + procedure p1(a: array of file of record end) := exit; + + end; + +begin end. \ No newline at end of file diff --git a/TestSuite/errors/err0254.pas b/TestSuite/errors/err0254.pas new file mode 100644 index 000000000..be393bd6f --- /dev/null +++ b/TestSuite/errors/err0254.pas @@ -0,0 +1,10 @@ +type + t1 = class + + constructor := exit; + + procedure p1(a: set of file of record end) := exit; + + end; + +begin end. \ No newline at end of file diff --git a/TestSuite/errors/err0255.pas b/TestSuite/errors/err0255.pas new file mode 100644 index 000000000..a901f8db4 --- /dev/null +++ b/TestSuite/errors/err0255.pas @@ -0,0 +1,10 @@ +type + t1 = class + + constructor := exit; + + procedure p1(a: array of set of record end) := exit; + + end; + +begin end. \ No newline at end of file diff --git a/TestSuite/errors/err0256.pas b/TestSuite/errors/err0256.pas new file mode 100644 index 000000000..07ef2c7bb --- /dev/null +++ b/TestSuite/errors/err0256.pas @@ -0,0 +1,10 @@ +type + t1 = class + + constructor := exit; + + procedure p1(a: array of array of record end) := exit; + + end; + +begin end. \ No newline at end of file diff --git a/TestSuite/errors/err0257.pas b/TestSuite/errors/err0257.pas new file mode 100644 index 000000000..8ffb0d412 --- /dev/null +++ b/TestSuite/errors/err0257.pas @@ -0,0 +1,10 @@ +type + t1 = class + + constructor := exit; + + procedure p1(a: array[,] of record end) := exit; + + end; + +begin end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 3a712adc4..3b2dac4c7 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -13377,6 +13377,47 @@ namespace PascalABCCompiler.TreeConverter } } + private void check_array_on_complex_type(SyntaxTree.array_type type) + { + SyntaxTree.array_type arr = type as SyntaxTree.array_type; + if (arr.indexers != null && arr.indexers.indexers.Count > 0 && arr.indexers.indexers[0] != null) + AddError(get_location(type), "STRUCT_TYPE_DEFINITION_IN_FORMAL_PARAM"); + if (arr.elements_type is SyntaxTree.array_type) + check_array_on_complex_type(arr.elements_type as SyntaxTree.array_type); + else if (arr.elements_type is SyntaxTree.class_definition) + AddError(get_location(arr.elements_type), "STRUCT_TYPE_DEFINITION_IN_FORMAL_PARAM"); + else if (arr.elements_type is SyntaxTree.set_type_definition) + check_set_on_complex_type(arr.elements_type as set_type_definition); + else if (arr.elements_type is SyntaxTree.file_type) + check_file_on_complex_type(arr.elements_type as file_type); + } + + private void check_set_on_complex_type(SyntaxTree.set_type_definition type) + { + SyntaxTree.set_type_definition set = type as SyntaxTree.set_type_definition; + if (set.of_type is SyntaxTree.array_type) + check_array_on_complex_type(set.of_type as SyntaxTree.array_type); + else if (set.of_type is SyntaxTree.class_definition) + AddError(get_location(set.of_type), "STRUCT_TYPE_DEFINITION_IN_FORMAL_PARAM"); + else if (set.of_type is SyntaxTree.file_type) + check_file_on_complex_type(set.of_type as file_type); + else if (set.of_type is SyntaxTree.set_type_definition) + check_set_on_complex_type(set.of_type as set_type_definition); + } + + private void check_file_on_complex_type(SyntaxTree.file_type type) + { + SyntaxTree.file_type file = type as SyntaxTree.file_type; + if (file.file_of_type is SyntaxTree.array_type) + check_array_on_complex_type(file.file_of_type as SyntaxTree.array_type); + else if (file.file_of_type is SyntaxTree.class_definition) + AddError(get_location(file.file_of_type), "STRUCT_TYPE_DEFINITION_IN_FORMAL_PARAM"); + else if (file.file_of_type is SyntaxTree.file_type) + check_file_on_complex_type(file.file_of_type as file_type); + else if (file.file_of_type is SyntaxTree.set_type_definition) + check_set_on_complex_type(file.file_of_type as set_type_definition); + } + public void check_parameter_on_complex_type(SyntaxTree.type_definition type) { SyntaxTree.array_type arr = type as SyntaxTree.array_type; @@ -13385,6 +13426,21 @@ namespace PascalABCCompiler.TreeConverter { AddError(get_location(type), "STRUCT_TYPE_DEFINITION_IN_FORMAL_PARAM"); } + if (arr != null) + { + check_array_on_complex_type(arr); + return; + } + if (type is SyntaxTree.set_type_definition) + { + check_set_on_complex_type(type as SyntaxTree.set_type_definition); + return; + } + else if (type is SyntaxTree.file_type) + { + check_file_on_complex_type(type as SyntaxTree.file_type); + return; + } if (context.top_function is common_method_node && (context.converted_type.IsInterface || context.top_function.polymorphic_state == SemanticTree.polymorphic_state.ps_virtual_abstract ) && (type is function_header || type is procedure_header)) AddError(get_location(type), "ANONYMOUS_DELEGATE_IN_INTERFACE_NOT_ALLOWED");