diff --git a/Compiler/Compiler.cs b/Compiler/Compiler.cs index 027f296c6..3c97424ae 100644 --- a/Compiler/Compiler.cs +++ b/Compiler/Compiler.cs @@ -2709,16 +2709,19 @@ namespace PascalABCCompiler if (!PCUFileNamesDictionary.TryGetValue(cacheKey, out var fileNameWithPriority)) { - if (FindFileWithExtensionInDirs(fileName, out _, currentPath) is string resultFileName1) + if (Path.GetExtension(fileName) != CompilerOptions.CompiledUnitExtension) + fileNameWithPriority = null; + + else if (FindFileWithExtensionInDirs(fileName, out _, currentPath) is string resultFileName1) fileNameWithPriority = Tuple.Create(resultFileName1, 1); - else if (FindFileWithExtensionInDirs(Path.GetFileName(fileName), out _, CompilerOptions.OutputDirectory) is string resultFileName2) + else if (CompilerOptions.OutputDirectory != CompilerOptions.SourceFileDirectory && FindFileWithExtensionInDirs(Path.GetFileName(fileName), out _, CompilerOptions.OutputDirectory) is string resultFileName2) fileNameWithPriority = Tuple.Create(resultFileName2, 2); else if (FindFileWithExtensionInDirs(fileName, out var dirIndex, CompilerOptions.SearchDirectories.ToArray()) is string resultFileName3) fileNameWithPriority = Tuple.Create(resultFileName3, 3 + dirIndex); else fileNameWithPriority = null; - PCUFileNamesDictionary[cacheKey] = fileNameWithPriority; + PCUFileNamesDictionary[cacheKey] = fileNameWithPriority; } folderPriority = fileNameWithPriority?.Item2 ?? 0; @@ -2730,8 +2733,9 @@ namespace PascalABCCompiler var cacheKey = Tuple.Create(fileName.ToLower(), currentPath?.ToLower()); if (!SourceFileNamesDictionary.TryGetValue(cacheKey, out var fileNameWithPriority)) - { - if (FindSourceFileNameInDirs(fileName, out _, currentPath) is string resultFileName1) + { + + if (FindSourceFileNameInDirs(fileName, out _, currentPath) is string resultFileName1) fileNameWithPriority = Tuple.Create(resultFileName1, 1); else if (FindSourceFileNameInDirs(fileName, out var dirIndex, CompilerOptions.SearchDirectories.ToArray()) is string resultFileName2) fileNameWithPriority = Tuple.Create(resultFileName2, 3 + dirIndex); @@ -3362,8 +3366,18 @@ namespace PascalABCCompiler // It's not always possible to solve by re-ordering the references, since there are cases of // mutually-dependent assemblies (i.e. dependency loops) in the wild. foreach (var reference in referenceDirectives) - PreloadReference(reference); - + { + try + { + PreloadReference(reference); + } + catch (FileLoadException ex) + { + throw new CommonCompilerError(ex.Message, compilationUnit.SyntaxTree.file_name, reference.location.begin_line_num, reference.location.end_line_num); + } + } + + foreach (var reference in referenceDirectives) CompileReference(dlls, reference); diff --git a/Languages/Pascal/PascalABCParserNewSaushkin/ABCPascal.y b/Languages/Pascal/PascalABCParserNewSaushkin/ABCPascal.y index 5c7b39492..3f4cf26a9 100644 --- a/Languages/Pascal/PascalABCParserNewSaushkin/ABCPascal.y +++ b/Languages/Pascal/PascalABCParserNewSaushkin/ABCPascal.y @@ -3375,8 +3375,6 @@ expr_l1_for_lambda expr_dq : relop_expr { $$ = $1; } - | tkAwait relop_expr - { $$ = new await_node($2 as expression, @$); } | expr_dq tkDoubleQuestion relop_expr { $$ = new double_question_node($1 as expression, $3 as expression, @$);} ; @@ -4160,6 +4158,8 @@ factor $$ = new nil_const(); $$.source_context = @$; } + | tkAwait factor + { $$ = new await_node($2 as expression, @$); } | literal_or_number { $$ = $1; } | default_expr diff --git a/Localization/DefaultLang.resources b/Localization/DefaultLang.resources index 13b78889d..f65cae790 100644 Binary files a/Localization/DefaultLang.resources and b/Localization/DefaultLang.resources differ diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 3de9348f9..2cac39046 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -4707,9 +4707,12 @@ namespace PascalABCCompiler.NETGenerator { ICommonTypeNode ctn = init_value.type as ICommonTypeNode; IExpressionNode[] FieldValues = init_value.FieldValues; - ICommonClassFieldNode[] Fields = ctn.fields; + List Fields = new List(); + foreach (var field in ctn.fields) + if (field.polymorphic_state != polymorphic_state.ps_static) + Fields.Add(field); - for (int i = 0; i < Fields.Length; i++) + for (int i = 0; i < Fields.Count; i++) { FldInfo field = helper.GetField(Fields[i]); if (FieldValues[i] is IArrayInitializer) @@ -4750,9 +4753,12 @@ namespace PascalABCCompiler.NETGenerator { ICommonTypeNode ctn = init_value.type as ICommonTypeNode; IConstantNode[] FieldValues = init_value.FieldValues; - ICommonClassFieldNode[] Fields = ctn.fields; + List Fields = new List(); + foreach (var field in ctn.fields) + if (field.polymorphic_state != polymorphic_state.ps_static) + Fields.Add(field); - for (int i = 0; i < Fields.Length; i++) + for (int i = 0; i < Fields.Count; i++) { FldInfo field = helper.GetField(Fields[i]); if (FieldValues[i] is IArrayConstantNode) diff --git a/SyntaxVisitors/YieldVisitors/RenameSameBlockLocalVarsVisitor.cs b/SyntaxVisitors/YieldVisitors/RenameSameBlockLocalVarsVisitor.cs index b0777dd3b..f051721f1 100644 --- a/SyntaxVisitors/YieldVisitors/RenameSameBlockLocalVarsVisitor.cs +++ b/SyntaxVisitors/YieldVisitors/RenameSameBlockLocalVarsVisitor.cs @@ -113,13 +113,16 @@ namespace SyntaxVisitors return; } + var newNameCache = new Dictionary(); + var newLocalNames = var_def.vars.idents.Select(id => { var low = id.name.ToLower(); var newName = this.CreateNewVariableName(low); //BlockNamesStack[CurrentLevel].Add(low, newName); - BlockNamesStack[CurrentLevel][low] = newName; + //BlockNamesStack[CurrentLevel][low] = newName; + newNameCache[low] = newName; return new ident(newName, id.source_context); }); @@ -130,6 +133,8 @@ namespace SyntaxVisitors Replace(var_def, newVS); listNodes[listNodes.Count - 1] = newVS; //SSM 8.11.18 ProcessNode(newVS.inital_value); // SSM 10.06.2020 #2103 + foreach (var key in newNameCache.Keys) + BlockNamesStack[CurrentLevel][key] = newNameCache[key]; //base.visit(newVS); // SSM 10.06.2020 - зачем обходить всё? } diff --git a/TestSuite/errors/err0538.pas b/TestSuite/errors/err0538.pas new file mode 100644 index 000000000..a0f78db91 --- /dev/null +++ b/TestSuite/errors/err0538.pas @@ -0,0 +1,8 @@ +//!Повторно объявленный идентификатор name +type + name = (name); + +begin + // Ожидался тип + var v1: name; +end. \ No newline at end of file diff --git a/TestSuite/errors/err0539.pas b/TestSuite/errors/err0539.pas new file mode 100644 index 000000000..e0e25e2b0 --- /dev/null +++ b/TestSuite/errors/err0539.pas @@ -0,0 +1,11 @@ +//!Количество полей не совпадает с количеством полей в записи +type + r1 = record + a: byte; + static b: word; + end; + +begin + // Работает, но не должно + var a: r1 := (a: 1; b: 2); +end. \ No newline at end of file diff --git a/TestSuite/recinit3.pas b/TestSuite/recinit3.pas new file mode 100644 index 000000000..956111e24 --- /dev/null +++ b/TestSuite/recinit3.pas @@ -0,0 +1,11 @@ +type + r1 = record + a: byte; + static b: word; + end; + +begin + //Ошибка: Количество полей не совпадает с количеством полей в записи + var a: r1 := (a: 1); + assert(a.a = 1); +end. \ No newline at end of file diff --git a/TestSuite/yield8.pas b/TestSuite/yield8.pas new file mode 100644 index 000000000..d58afdcbb --- /dev/null +++ b/TestSuite/yield8.pas @@ -0,0 +1,29 @@ +function V(n: byte) := 1; + +function f1: sequence of integer; +begin + //Ошибка: Ожидалось имя процедуры или функции + var v := V(0); + // Если закомментировать эту строчку - предыдущая строчка работает + yield v; +end; + +function f2: sequence of integer; +begin + //Ошибка: Ожидалось имя процедуры или функции + var v := V(0); + var w := v + 1; + // Если закомментировать эту строчку - предыдущая строчка работает + yield w; +end; + +begin + var i := 0; + foreach var j in f1 do + i := j; + assert(i = 1); + + foreach var j in f2 do + i := j; + assert(i = 2); +end. \ No newline at end of file diff --git a/TreeConverter/TreeConversion/syntax_tree_visitor.cs b/TreeConverter/TreeConversion/syntax_tree_visitor.cs index 3c516006a..e0d4d0612 100644 --- a/TreeConverter/TreeConversion/syntax_tree_visitor.cs +++ b/TreeConverter/TreeConversion/syntax_tree_visitor.cs @@ -111,6 +111,8 @@ namespace PascalABCCompiler.TreeConverter { //convertion_data_and_alghoritms.__i = 0; Initialize(initializationData); + + this.docs = initializationData.docs; //comp_units=UsedUnits; //visit(SyntaxUnit //SyntaxTreeToSemanticTreeConverter.interface_using_list = namespaces; @@ -122,6 +124,9 @@ namespace PascalABCCompiler.TreeConverter { Initialize(initializationData); + if (this.docs != null) + this.docs = initializationData.docs; + using_list.AddRange(initializationData.interfaceNamespaces); interface_using_list.AddRange(initializationData.interfaceNamespaces); using_list.AddRange(initializationData.implementationNamespaces); @@ -150,8 +155,6 @@ namespace PascalABCCompiler.TreeConverter SymbolTable.CaseSensitive = SemanticRulesConstants.SymbolTableCaseSensitive; - if (docs != null) - this.docs = initializationData.docs; this.debug = initializationData.debug; this.debugging = initializationData.debugging; this.for_intellisense = initializationData.forIntellisense; @@ -12208,6 +12211,8 @@ namespace PascalABCCompiler.TreeConverter context.check_name_free(name, loc); is_direct_type_decl = true; type_node tn = convert_strong(_type_declaration.type_def); + if (_type_declaration.type_def is enum_type_definition) + context.check_name_free(name, loc); assign_doc_info(tn,_type_declaration); is_direct_type_decl = false; if (_type_declaration.type_def is SyntaxTree.named_type_reference|| @@ -15592,13 +15597,14 @@ namespace PascalABCCompiler.TreeConverter private record_initializer ConvertRecordInitializer(common_type_node ctn, record_initializer constant) { location loc = constant.location; + var non_static_fields = ctn.fields.Where(x => !x.IsStatic).ToArray(); if (!ctn.is_value_type) AddError(loc, "RECORD_CONST_NOT_ALLOWED_{0}", ctn.name); - if (ctn.fields.Count != constant.record_const_definition_list.Count) + if (non_static_fields.Length != constant.record_const_definition_list.Count) AddError(loc, "INVALID_RECORD_CONST_FIELD_COUNT"); constant.type = ctn; constant.field_values.Clear(); - for (int i = 0; i < ctn.fields.Count; i++) + for (int i = 0; i < non_static_fields.Length; i++) { class_field cf = ctn.fields[i]; if (cf.name.ToLower() != constant.record_const_definition_list[i].name.name.ToLower()) diff --git a/bin/Lib/ABCObjects.pas b/bin/Lib/ABCObjects.pas index ef2d4971a..708b732b5 100644 --- a/bin/Lib/ABCObjects.pas +++ b/bin/Lib/ABCObjects.pas @@ -10,7 +10,6 @@ unit ABCObjects; //{$apptype windows} {$reference '%GAC%\System.Windows.Forms.dll'} {$reference '%GAC%\System.Drawing.dll'} -{$gendoc true} interface diff --git a/bin/Lib/ABCObjects.xml b/bin/Lib/ABCObjects.xml deleted file mode 100644 index 90226e328..000000000 --- a/bin/Lib/ABCObjects.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/bin/Lib/CRT.pas b/bin/Lib/CRT.pas index e934f1d11..d2c161d6d 100644 --- a/bin/Lib/CRT.pas +++ b/bin/Lib/CRT.pas @@ -7,7 +7,6 @@ unit CRT; {$apptype console} -{$gendoc true} interface diff --git a/bin/Lib/CRT.xml b/bin/Lib/CRT.xml deleted file mode 100644 index 56c7dbfac..000000000 --- a/bin/Lib/CRT.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/bin/Lib/GraphABC.pas b/bin/Lib/GraphABC.pas index 970f5802e..5dbbe0e22 100644 --- a/bin/Lib/GraphABC.pas +++ b/bin/Lib/GraphABC.pas @@ -8,7 +8,6 @@ unit GraphABC; {$apptype windows} {$reference '%GAC%\System.Windows.Forms.dll'} {$reference '%GAC%\System.Drawing.dll'} -{$gendoc true} interface diff --git a/bin/Lib/GraphABC.xml b/bin/Lib/GraphABC.xml deleted file mode 100644 index 254fd01fe..000000000 --- a/bin/Lib/GraphABC.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/bin/Lib/PABCSystem.pas b/bin/Lib/PABCSystem.pas index fbdee0e67..9b503384c 100644 --- a/bin/Lib/PABCSystem.pas +++ b/bin/Lib/PABCSystem.pas @@ -7,8 +7,6 @@ unit PABCSystem; {$zerobasedstrings off} -{$gendoc true} - // Default Application type {$apptype console} diff --git a/bin/Lib/PABCSystem.xml b/bin/Lib/PABCSystem.xml deleted file mode 100644 index 09c905ca8..000000000 --- a/bin/Lib/PABCSystem.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file