diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 28509c3d..ab1adb7d 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -27,7 +27,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Setup GitVersion uses: gittools/actions/gitversion/setup@v3.0.0 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a6032768..527a96af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,7 +61,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Setup GitReleaseManager uses: gittools/actions/gitreleasemanager/setup@v3.0.0 with: diff --git a/Directory.Build.props b/Directory.Build.props index 8b943f64..0740392c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - net8.0 + net9.0 enable enable true diff --git a/Readme.md b/Readme.md index 1c2f3225..b13025ba 100644 --- a/Readme.md +++ b/Readme.md @@ -173,7 +173,7 @@ let s = v2d as string ### Требования -- .NET 8 SDK +- .NET 9 SDK ### Сборка После клонирования репозитория идём в папку проекта `HydraScript`. diff --git a/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs b/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs index 4de6ff44..b76cfac4 100644 --- a/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs +++ b/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs @@ -5,13 +5,11 @@ namespace HydraScript.Application.StaticAnalysis.Impl; internal class FunctionWithUndefinedReturnStorage : IFunctionWithUndefinedReturnStorage { - private readonly Dictionary _declarations = []; - private readonly Dictionary _keysWithOrder = []; + private readonly OrderedDictionary _declarations = []; public void Save(FunctionSymbol symbol, FunctionDeclaration declaration) { _declarations[symbol.Id] = declaration; - _keysWithOrder[symbol.Id] = _declarations.Count; } public FunctionDeclaration Get(FunctionSymbol symbol) @@ -19,22 +17,19 @@ public FunctionDeclaration Get(FunctionSymbol symbol) if (!_declarations.Remove(symbol.Id, out var declaration)) throw new InvalidOperationException(message: "Cannot get function that has not been saved"); - _keysWithOrder.Remove(symbol.Id); return declaration; } public void RemoveIfPresent(FunctionSymbol symbol) { _declarations.Remove(symbol.Id); - _keysWithOrder.Remove(symbol.Id); } - public IEnumerable Flush() => _declarations - .OrderBy(kvp => _keysWithOrder[kvp.Key]) + public IEnumerable Flush() => _declarations.Keys.ToList() .Select(x => { - _declarations.Remove(x.Key); - _keysWithOrder.Remove(x.Key); - return x.Value; + var decl = _declarations[x]; + _declarations.Remove(x); + return decl; }); } \ No newline at end of file diff --git a/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs b/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs index d374898a..9c8f7a7a 100644 --- a/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs +++ b/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs @@ -11,10 +11,10 @@ namespace HydraScript.Tests.Unit.IR; public class FunctionWithUndefinedReturnStorageTests { + const string functionName = nameof(functionName); [Fact] public void StorageIsEmptyAfterFlushTest() { - const string functionName = nameof(functionName); IFunctionWithUndefinedReturnStorage storage = new FunctionWithUndefinedReturnStorage(); var symbol = new FunctionSymbol( @@ -36,4 +36,66 @@ public void StorageIsEmptyAfterFlushTest() Assert.Empty(storage.Flush()); } + + [Fact] + public void StorageIsCorrectOrderTest() + { + FunctionDeclaration[] declarations = [ + new FunctionDeclaration( + name: new IdentifierReference(functionName), + returnTypeValue: Substitute.For(), + arguments: [], + new BlockStatement([])), + + new FunctionDeclaration( + name: new IdentifierReference(functionName), + returnTypeValue: Substitute.For(), + arguments: [], + new BlockStatement([])), + + new FunctionDeclaration( + name: new IdentifierReference(functionName), + returnTypeValue: Substitute.For(), + arguments: [], + new BlockStatement([])), + + new FunctionDeclaration( + name: new IdentifierReference(functionName), + returnTypeValue: Substitute.For(), + arguments: [], + new BlockStatement([])) + ]; + + IFunctionWithUndefinedReturnStorage storage = new FunctionWithUndefinedReturnStorage(); + + var removable = new FunctionSymbol( + id: "key2", + parameters: [], + "undefined", + isEmpty: false); + + storage.Save(new FunctionSymbol( + id: "key1", + parameters: [], + "undefined", + isEmpty: false), declaration: declarations[0]); + + storage.Save(removable, declaration: declarations[1]); + + storage.Save(new FunctionSymbol( + id: "key3", + parameters: [], + "undefined", + isEmpty: false), declaration: declarations[2]); + + storage.Save(new FunctionSymbol( + id: "key4", + parameters: [], + "undefined", + isEmpty: false), declaration: declarations[3]); + + storage.RemoveIfPresent(removable); + + Assert.Equal([declarations[0], declarations[2], declarations[3]], storage.Flush()); + } } \ No newline at end of file