Skip to content

fixed classic array creation with empty initialized - #82

Open
koenbeuk wants to merge 1 commit into
mainfrom
fix/empty-array-initialization
Open

fixed classic array creation with empty initialized#82
koenbeuk wants to merge 1 commit into
mainfrom
fix/empty-array-initialization

Conversation

@koenbeuk

@koenbeuk koenbeuk commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings August 1, 2026 23:49
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.55556% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...veSharp.Generator/Emitter/ExpressionTreeEmitter.cs 55.55% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes code generation edge cases in the Roslyn source generator where empty initializers could produce syntactically invalid emitted C# (e.g., trailing commas in Expression.MemberInit(...) and Expression.NewArrayInit(...) calls), and adds a regression test to cover an empty classic array initializer.

Changes:

  • Emit Expression.MemberInit(newExpr) / Expression.NewArrayInit(type) without a trailing argument list when the initializer is empty.
  • Add a generator test for new int[] { } to ensure the generated output compiles.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/ExpressiveSharp.Generator.Tests/ExpressiveGenerator/CollectionExpressionTests.cs Adds a regression test for an empty classic array initializer.
src/ExpressiveSharp.Generator/Emitter/ExpressionTreeEmitter.cs Adjusts emitter output to avoid generating invalid code for empty member/array initializers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +174 to +175
Assert.AreEqual(1, result.GeneratedTrees.Length);
Assert.IsFalse(result.Diagnostics.Any(d => d.Severity == Microsoft.CodeAnalysis.DiagnosticSeverity.Error));
Comment on lines +1231 to +1233
AppendLine(bindingVars.Count == 0
? $"var {resultVar} = {Expr}.MemberInit({newVar});"
: $"var {resultVar} = {Expr}.MemberInit({newVar}, {string.Join(", ", bindingVars)});");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants