diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ceeb51f..93a31814 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: - uses: Brightspace/third-party-actions@actions/setup-dotnet with: dotnet-version: | - 7.0.x + 9.0.x - name: Build run: dotnet build -c Release diff --git a/Directory.Build.props b/Directory.Build.props index c1307957..bc3621c7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ true - 10.0 + 12.0 true true enable diff --git a/global.json b/global.json index d03eb395..db615a49 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "7.0.300", + "version": "9.0.101", "rollForward": "latestFeature" } } diff --git a/src/D2L.CodeStyle.Analyzers/Async/Generator/AsyncToSyncMethodTransformer.cs b/src/D2L.CodeStyle.Analyzers/Async/Generator/AsyncToSyncMethodTransformer.cs index a4218aaa..d77b904d 100644 --- a/src/D2L.CodeStyle.Analyzers/Async/Generator/AsyncToSyncMethodTransformer.cs +++ b/src/D2L.CodeStyle.Analyzers/Async/Generator/AsyncToSyncMethodTransformer.cs @@ -258,6 +258,9 @@ private ExpressionSyntax Transform( ExpressionSyntax expr ) .WithLeft( Transform( binExpr.Left ) ) .WithRight( Transform( binExpr.Right ) ), + CollectionExpressionSyntax collectionExpr => + collectionExpr.WithElements( Transform( collectionExpr.Elements ) ), + ConditionalExpressionSyntax condExpr => condExpr .WithCondition( Transform( condExpr.Condition ) ) .WithWhenTrue( Transform( condExpr.WhenTrue ) ) @@ -352,6 +355,17 @@ private VariableDesignationSyntax Transform( VariableDesignationSyntax des ) _ => UnhandledSyntax( des ) }; + private SeparatedSyntaxList Transform( + SeparatedSyntaxList original + ) => SyntaxFactory.SeparatedList( + original.Select( elem => elem switch { + ExpressionElementSyntax ee => ee.WithExpression( Transform( ee.Expression ) ), + SpreadElementSyntax sp => sp.WithExpression( Transform( sp.Expression ) ), + _ => UnhandledSyntax( elem ) + } ), + original.GetSeparators() + ); + private StatementSyntax Transform( ExpressionStatementSyntax exprStmt ) { var result = Transform( exprStmt.Expression ); diff --git a/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/AsyncToSyncMethodTransformerTests.cs b/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/AsyncToSyncMethodTransformerTests.cs index 60ec59c9..067f4150 100644 --- a/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/AsyncToSyncMethodTransformerTests.cs +++ b/tests/D2L.CodeStyle.Analyzers.Test/Async/Generator/AsyncToSyncMethodTransformerTests.cs @@ -633,6 +633,41 @@ public void ImplicitObjectCreation() { Assert.AreEqual( "[Blocking] T Hello() { return new( Foo() ); }", actual.Value.ToFullString() ); } + [Test] + public void CollectionSyntax() { + var actual = Transform( + """ + [GenerateSync] + async Task> HelloAsync() + => [ + await FooAsync(), + 3, + ..(await BarAsync()), + 4, + await XAsync() + await YAsync() + ]; + """ + ); + + + Assert.IsTrue( actual.Success ); + Assert.IsEmpty( actual.Diagnostics ); + Assert.AreEqual( + """ + [Blocking] + IEnumerable Hello() + => [ + Foo(), + 3, + ..(Bar()), + 4, + X() + Y() + ]; + """, + actual.Value.ToFullString() + ); + + } // loosly assert that the right sorts of diagnostics came out private static void AssertDiagnostics( IEnumerable actual, params DiagnosticDescriptor[] expected ) {