From ce7dee8720c431a0d40dd48b90730ef02eeaa7a9 Mon Sep 17 00:00:00 2001
From: EvilBeaver <ovsiankin.aa@gmail.com>
Date: Sat, 11 Nov 2023 23:19:27 +0300
Subject: [PATCH] =?UTF-8?q?Revert=20"fixes=20#1354=20=D0=BF=D0=B5=D1=80?=
 =?UTF-8?q?=D0=B5=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD?=
 =?UTF-8?q?=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=BE=D0=B2=20?=
 =?UTF-8?q?=D0=B3=D0=BB=D0=BE=D0=B1=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B3?=
 =?UTF-8?q?=D0=BE=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0?=
 =?UTF-8?q?"=20Revert=20"=D0=92=D0=BE=D0=BB=D1=88=D0=B5=D0=B1=D0=BD=D0=B0?=
 =?UTF-8?q?=D1=8F=20=D0=B0=D0=BD=D0=BD=D0=BE=D1=82=D0=B0=D1=86=D0=B8=D1=8F?=
 =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5?=
 =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D1=82=D0=B0=D0=BD=D0=B4?=
 =?UTF-8?q?=D0=B0=D1=80=D1=82=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BC=D0=B5=D1=82?=
 =?UTF-8?q?=D0=BE=D0=B4=D0=B0"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Compilation/Binding/BindingExtensions.cs  | 15 -------
 .../Binding/BslOverrideAttribute.cs           | 23 -----------
 .../Localization/BilingualString.cs           | 23 +----------
 .../Localization/LocalizationExtensions.cs    | 24 -----------
 .../Compiler/CompilerHelpers.cs               | 12 ++----
 .../Compiler/ModuleCompiler.cs                |  2 +-
 .../Compiler/StackMachineCodeGenerator.cs     | 22 ++++------
 tests/engine-behaviors.os                     | 40 +------------------
 8 files changed, 13 insertions(+), 148 deletions(-)
 delete mode 100644 src/OneScript.Core/Compilation/Binding/BslOverrideAttribute.cs
 delete mode 100644 src/OneScript.Language/Localization/LocalizationExtensions.cs

diff --git a/src/OneScript.Core/Compilation/Binding/BindingExtensions.cs b/src/OneScript.Core/Compilation/Binding/BindingExtensions.cs
index 7f3998257..6c30c4961 100644
--- a/src/OneScript.Core/Compilation/Binding/BindingExtensions.cs
+++ b/src/OneScript.Core/Compilation/Binding/BindingExtensions.cs
@@ -4,11 +4,7 @@ This Source Code Form is subject to the terms of the
 was not distributed with this file, You can obtain one
 at http://mozilla.org/MPL/2.0/.
 ----------------------------------------------------------*/
-
-using System.Linq;
-using System.Reflection;
 using OneScript.Contexts;
-using OneScript.Language.SyntaxAnalysis.AstNodes;
 using OneScript.Runtime.Binding;
 using OneScript.Values;
 
@@ -44,16 +40,5 @@ public static IFieldSymbol ToSymbol(this BslFieldInfo info)
         {
             return new BslFieldSymbol { Field = info };
         }
-
-        public static bool IsUniqueMethod(this SymbolTable table, MethodNode astNode)
-        {
-            var isKnown = table.TryFindMethodBinding(astNode.Signature.MethodName, out _);
-            if (!isKnown)
-            {
-                return true;
-            }
-
-            return astNode.Annotations.Any(a => BslOverrideAttribute.AcceptsIdentifier(a.Name));
-        }
     }
 }
diff --git a/src/OneScript.Core/Compilation/Binding/BslOverrideAttribute.cs b/src/OneScript.Core/Compilation/Binding/BslOverrideAttribute.cs
deleted file mode 100644
index d2a361640..000000000
--- a/src/OneScript.Core/Compilation/Binding/BslOverrideAttribute.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-/*----------------------------------------------------------
-This Source Code Form is subject to the terms of the
-Mozilla Public License, v.2.0. If a copy of the MPL
-was not distributed with this file, You can obtain one
-at http://mozilla.org/MPL/2.0/.
-----------------------------------------------------------*/
-
-using System;
-using OneScript.Localization;
-
-namespace OneScript.Compilation.Binding
-{
-    [AttributeUsage(AttributeTargets.Method)]
-    public class BslOverrideAttribute : Attribute
-    {
-        public static readonly BilingualString OverrideAttributeName = new BilingualString("Переопределить", "Override");
-        
-        public static bool AcceptsIdentifier(string identifier)
-        {
-            return OverrideAttributeName.ContainsString(identifier);
-        }
-    }
-}
\ No newline at end of file
diff --git a/src/OneScript.Language/Localization/BilingualString.cs b/src/OneScript.Language/Localization/BilingualString.cs
index 6c7105576..a4aaf9f01 100644
--- a/src/OneScript.Language/Localization/BilingualString.cs
+++ b/src/OneScript.Language/Localization/BilingualString.cs
@@ -5,12 +5,11 @@ This Source Code Form is subject to the terms of the
 at http://mozilla.org/MPL/2.0/.
 ----------------------------------------------------------*/
 
-using System;
 using System.Globalization;
 
 namespace OneScript.Localization
 {
-    public class BilingualString : IEquatable<BilingualString>
+    public class BilingualString
     {
         private static readonly CultureInfo RussianCulture;
 
@@ -68,25 +67,5 @@ public static string Localize(string russian, string english)
 
             return russian;
         }
-
-        public bool Equals(BilingualString other)
-        {
-            if (ReferenceEquals(null, other)) return false;
-            if (ReferenceEquals(this, other)) return true;
-            return Russian == other.Russian && English == other.English;
-        }
-
-        public override bool Equals(object obj)
-        {
-            if (ReferenceEquals(null, obj)) return false;
-            if (ReferenceEquals(this, obj)) return true;
-            if (obj.GetType() != this.GetType()) return false;
-            return Equals((BilingualString)obj);
-        }
-
-        public override int GetHashCode()
-        {
-            return HashCode.Combine(Russian, English);
-        }
     }
 }
\ No newline at end of file
diff --git a/src/OneScript.Language/Localization/LocalizationExtensions.cs b/src/OneScript.Language/Localization/LocalizationExtensions.cs
deleted file mode 100644
index 1bb625242..000000000
--- a/src/OneScript.Language/Localization/LocalizationExtensions.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-/*----------------------------------------------------------
-This Source Code Form is subject to the terms of the
-Mozilla Public License, v.2.0. If a copy of the MPL
-was not distributed with this file, You can obtain one
-at http://mozilla.org/MPL/2.0/.
-----------------------------------------------------------*/
-
-using System;
-
-namespace OneScript.Localization
-{
-    public static class LocalizationExtensions
-    {
-        public static bool ContainsString(this BilingualString bi, string sample)
-        {
-            return ContainsString(bi, sample, StringComparison.CurrentCultureIgnoreCase);
-        }
-        
-        public static bool ContainsString(this BilingualString bi, string sample, StringComparison comparison)
-        {
-            return bi.Russian.Equals(sample, comparison) || bi.English.Equals(sample, comparison);
-        }
-    }
-}
\ No newline at end of file
diff --git a/src/OneScript.Native/Compiler/CompilerHelpers.cs b/src/OneScript.Native/Compiler/CompilerHelpers.cs
index 6159fcc5f..2afe69439 100644
--- a/src/OneScript.Native/Compiler/CompilerHelpers.cs
+++ b/src/OneScript.Native/Compiler/CompilerHelpers.cs
@@ -9,7 +9,6 @@ This Source Code Form is subject to the terms of the
 using System.Collections.Generic;
 using System.Linq;
 using System.Runtime.CompilerServices;
-using OneScript.Compilation.Binding;
 using OneScript.Contexts;
 using OneScript.Language.LexicalAnalysis;
 using OneScript.Language.SyntaxAnalysis.AstNodes;
@@ -50,15 +49,10 @@ public static object ClrValueFromLiteral(in Lexem lex)
 
         public static IEnumerable<Attribute> GetAnnotations(IEnumerable<AnnotationNode> annotations)
         {
-            return annotations.Select<AnnotationNode, Attribute>(a =>
-            {
-                if (BslOverrideAttribute.AcceptsIdentifier(a.Name))
-                {
-                    return new BslOverrideAttribute();
-                }
+            // Возможно будут какие-то маппинги на системные атрибуты, не только на BslAnnotation
+            // поэтому возвращаем Attribute[] а не BslAnnotation[]
 
-                return GetBslAnnotation(a);
-            }).ToList();
+            return annotations.Select(GetBslAnnotation).ToList();
         }
         
         public static BslAnnotationAttribute GetBslAnnotation(AnnotationNode node)
diff --git a/src/OneScript.Native/Compiler/ModuleCompiler.cs b/src/OneScript.Native/Compiler/ModuleCompiler.cs
index 2b295034e..61acb2044 100644
--- a/src/OneScript.Native/Compiler/ModuleCompiler.cs
+++ b/src/OneScript.Native/Compiler/ModuleCompiler.cs
@@ -79,7 +79,7 @@ private void RegisterLocalMethods(BslSyntaxNode module)
             foreach (var methodNode in methodsSection.Children.Cast<MethodNode>())
             {
                 var signature = methodNode.Signature;
-                if (!Symbols.IsUniqueMethod(methodNode))
+                if (Symbols.TryFindMethodBinding(signature.MethodName, out _))
                 {
                     AddError(LocalizedErrors.DuplicateMethodDefinition(signature.MethodName), signature.Location);
                     continue;
diff --git a/src/ScriptEngine/Compiler/StackMachineCodeGenerator.cs b/src/ScriptEngine/Compiler/StackMachineCodeGenerator.cs
index 4cb64a755..e361f4e9f 100644
--- a/src/ScriptEngine/Compiler/StackMachineCodeGenerator.cs
+++ b/src/ScriptEngine/Compiler/StackMachineCodeGenerator.cs
@@ -287,16 +287,15 @@ protected override void VisitMethod(MethodNode methodNode)
             methodInfo.SetRuntimeParameters(entryPoint, GetVariableNames(methodCtx));
             
             SymbolBinding binding;
-            if (_ctx.IsUniqueMethod(methodNode))
+            try
             {
                 binding = _ctx.DefineMethod(methodInfo.ToSymbol());
             }
-            else
+            catch (CompilerException)
             {
                 AddError(LocalizedErrors.DuplicateMethodDefinition(signature.MethodName), signature.Location);
                 binding = default;
             }
-
             _module.MethodRefs.Add(binding);
             _module.Methods.Add(methodInfo);
         }
@@ -1103,21 +1102,14 @@ private void VisitConstant(in Lexem constant)
             AddCommand(OperationCode.PushConst, num);
         }
 
-        private IEnumerable<Attribute> GetAnnotationAttributes(AnnotatableNode node)
+        private IEnumerable<BslAnnotationAttribute> GetAnnotationAttributes(AnnotatableNode node)
         {
-            var mappedAnnotations = new List<Attribute>();
+            var mappedAnnotations = new List<BslAnnotationAttribute>();
             foreach (var annotation in node.Annotations)
             {
-                if (BslOverrideAttribute.AcceptsIdentifier(annotation.Name))
-                {
-                    mappedAnnotations.Add(new BslOverrideAttribute());
-                }
-                else
-                {
-                    var anno = new BslAnnotationAttribute(annotation.Name);
-                    anno.SetParameters(GetAnnotationParameters(annotation));
-                    mappedAnnotations.Add(anno);
-                }
+                var anno = new BslAnnotationAttribute(annotation.Name);
+                anno.SetParameters(GetAnnotationParameters(annotation));
+                mappedAnnotations.Add(anno);
             }
 
             return mappedAnnotations;
diff --git a/tests/engine-behaviors.os b/tests/engine-behaviors.os
index f1088a9bd..01867ddf2 100644
--- a/tests/engine-behaviors.os
+++ b/tests/engine-behaviors.os
@@ -52,8 +52,6 @@
 	ВсеТесты.Добавить("ТестДолжен_ПроверитьИнформацияОбОшибкеВнеИсключения");
 	ВсеТесты.Добавить("ТестДолжен_ПроверитьПередачуПараметровПоСсылке");
 	ВсеТесты.Добавить("ТестДолжен_ПроверитьСравнениеНаБольшеМеньше");
-	ВсеТесты.Добавить("ТестДолжен_ПроверитьНевозможностьПереопределенияГлобальногоКонтекста");
-	ВсеТесты.Добавить("ТестДолжен_ПроверитьВозможностьПереопределенияГлобальногоКонтекста");
 	
 	Возврат ВсеТесты;
 
@@ -688,44 +686,8 @@
 		
 	юТест.ПроверитьКодСОшибкой(
 		"Массив = Новый Массив(1);
-		|Массив2 = Новый Массив(1);
+		|Массив2 = Новый Массив(1);;
 		|Рез = (Массив <= Массив2);",
 		Ошибка, "Для одинаковых объектов" );
 	
 КонецПроцедуры
-
-Процедура ТестДолжен_ПроверитьНевозможностьПереопределенияГлобальногоКонтекста() Экспорт
-    
-    Код = "Функция СтрНайти(знач Стр1, знач Стр2)
-    |	Возврат -1;
-    |КонецФункции
-    |
-    |Рез = СтрНайти(""Ай!"", ""!"");
-    |Если Рез < 0 Тогда
-    |	Сообщить(""Ой!"");
-    |КонецЕсли";
-    
-    юТест.ПроверитьКодСОшибкой(Код, "СтрНайти");
-    
-    юТест.ПроверитьКодСОшибкой("#native" + Символы.ПС + Код, "СтрНайти");
-    
-КонецПроцедуры
-
-Процедура ТестДолжен_ПроверитьВозможностьПереопределенияГлобальногоКонтекста() Экспорт
-    
-    Код = "&Переопределить
-    |Функция СтрНайти(знач Стр1, знач Стр2)
-    |	Возврат -1;
-    |КонецФункции
-    |
-    |Функция Проверить() Экспорт
-    |   Возврат СтрНайти(""1"", ""1"");
-    |КонецФункции";
-    
-    СкриптСтек = ЗагрузитьСценарийИзСтроки(Код);
-    СкриптНатив = ЗагрузитьСценарийИзСтроки("#native" + Символы.ПС + Код);
-    
-    юТест.ПроверитьРавенство(-1, СкриптСтек.Проверить());
-    юТест.ПроверитьРавенство(-1, СкриптНатив.Проверить());
-    
-КонецПроцедуры