From 1dbf625c3381bbcc3468ea10f0a1c7342e08d36b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=9F=D0=BE=D0=B3=D0=BE=D1=80=D0=B5=D0=BB=D0=BE=D0=B2?= Date: Thu, 13 Dec 2018 11:11:07 +0300 Subject: [PATCH] fix #1408 --- .../PatternsDesugaringVisitor.cs | 19 +++++++++++++++++++ _GenerateAllSetups.bat | 2 ++ _ReBuildRelease.bat | 2 ++ _RebuildReleaseAndBuildUnits.bat | 2 ++ bin/Lng/Rus/SyntaxTreeVisitorsErrors.dat | 1 + 5 files changed, 26 insertions(+) diff --git a/SyntaxVisitors/SugarVisitors/PatternsDesugaringVisitor.cs b/SyntaxVisitors/SugarVisitors/PatternsDesugaringVisitor.cs index 2e4238e44..68afb482b 100644 --- a/SyntaxVisitors/SugarVisitors/PatternsDesugaringVisitor.cs +++ b/SyntaxVisitors/SugarVisitors/PatternsDesugaringVisitor.cs @@ -89,13 +89,32 @@ namespace SyntaxVisitors.SugarVisitors //AddDefinitionsInUpperStatementList(matchWith, new[] { new var_statement(cachedExpression, matchWith.expr) }); // Преобразование из сахара в известную конструкцию каждого case + var usedDeconstructionTypes = new HashSet(); foreach (var patternCase in matchWith.case_list.elements) { if (patternCase == null) continue; if (patternCase.pattern is deconstructor_pattern) + { + // Проверяем встречался ли уже такой тип при деконструкции + var deconstructionType = (patternCase.pattern as deconstructor_pattern). + type as named_type_reference; + if (deconstructionType != null && + deconstructionType.names != null && + deconstructionType.names.Count != 0) + { + var deconstructionTypeName = deconstructionType.names[0].name; + if (usedDeconstructionTypes.Contains(deconstructionTypeName)) + { + throw new SyntaxVisitorError("REPEATED_DECONSTRUCTION_TYPE", + patternCase.pattern.source_context); + } + usedDeconstructionTypes.Add(deconstructionTypeName); + } + DesugarDeconstructorPatternCase(matchWith.expr, patternCase); + } } if (matchWith.defaultAction != null) diff --git a/_GenerateAllSetups.bat b/_GenerateAllSetups.bat index e6948d4e4..77b20bd07 100644 --- a/_GenerateAllSetups.bat +++ b/_GenerateAllSetups.bat @@ -18,6 +18,8 @@ Utils\ReplaceInFiles\ReplaceInFiles.exe Configuration\Version.defs Configuration if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" ( "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" /t:rebuild /property:Configuration=Release PascalABCNET.sln +) else if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" ( +"%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" /t:rebuild /property:Configuration=Release PascalABCNET.sln ) else ( "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" /t:rebuild /property:Configuration=Release PascalABCNET.sln ) diff --git a/_ReBuildRelease.bat b/_ReBuildRelease.bat index a6208ab84..4a7dcbc12 100644 --- a/_ReBuildRelease.bat +++ b/_ReBuildRelease.bat @@ -1,5 +1,7 @@ if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" ( "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" /t:rebuild /verbosity:d /property:Configuration=Release PascalABCNET.sln +) else if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" ( +"%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" /t:rebuild /verbosity:d /property:Configuration=Release PascalABCNET.sln ) else ( "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" /t:rebuild /verbosity:d /property:Configuration=Release PascalABCNET.sln ) diff --git a/_RebuildReleaseAndBuildUnits.bat b/_RebuildReleaseAndBuildUnits.bat index cca58dc61..1daac9e4d 100644 --- a/_RebuildReleaseAndBuildUnits.bat +++ b/_RebuildReleaseAndBuildUnits.bat @@ -1,5 +1,7 @@ if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" ( "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" /t:rebuild /property:Configuration=Release /p:Platform="Any CPU" PascalABCNET.sln +) else if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" ( +"%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" /t:rebuild /property:Configuration=Release /p:Platform="Any CPU" PascalABCNET.sln ) else ( "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" /t:rebuild /property:Configuration=Release /p:Platform="Any CPU" PascalABCNET.sln ) diff --git a/bin/Lng/Rus/SyntaxTreeVisitorsErrors.dat b/bin/Lng/Rus/SyntaxTreeVisitorsErrors.dat index 30d9dcfe3..e84fff2f1 100644 --- a/bin/Lng/Rus/SyntaxTreeVisitorsErrors.dat +++ b/bin/Lng/Rus/SyntaxTreeVisitorsErrors.dat @@ -16,6 +16,7 @@ LAMBDA_EXPRESSIONS_CANNOT_CONTAIN_YIELD=Лямбда-выражения не м PATTERN_MATHING_IS_NOT_SUPPORTED_IN_THIS_CONTEXT=Сопоставление с образцом не поддерживается в данном контексте ONLY_ONE_DECONSTRUCT_ALLOWED=Можно определить только один пользовательский деконструктор +REPEATED_DECONSTRUCTION_TYPE=Повторение типов при сопоставлении с образцом Var_{0}_is_already_defined=Переменная {0} уже определена