Repository navigation
Write a typeless C# list as a collection expression [patch] - #442
Merged
Merged
Conversation
A construction with no type, the list on its own, came out as bare braces in C#. Those are only an array's initialiser, so a List<T> field or local failed with CS0622, and a return, assignment or argument did not parse at all. C# now writes a collection expression ([1, 2]), which fits an array and a List<T> alike in every one of those positions. A table of lists stays one element per line, and a list with designated members is still an object initialiser. Fixes #418. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5vywfZJXnxcJfXxVi
Name the opening, closing and padding marks once rather than choosing each at its use, which takes SonarCloud's S3776 count from 16 back under 15. Output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5vywfZJXnxcJfXxVi
…ss-list # Conflicts: # Coder.Test/Languages/CSharpGeneratedSourceCompilesTests.cs
…ss-list # Conflicts: # Coder.Test/Languages/CSharpGeneratedSourceCompilesTests.cs
|
This was referenced Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #418
What was wrong
C# wrote a
ConstructionExpressionwith no type (the list on its own) as bare braces,{ 1, 2 }. C# accepts those only as an array's initialiser, so:List<int>field or local failed with CS0622return, an assignment or an argument didn't parse at all (CS1525)Change
CSharpGenerator.GenerateConstructionnow writes a typeless list as a collection expression ([1, 2], and[]when empty). That form works for arrays andList<T>in every one of those positions. Nothing else changes:[ [1, 2], [3, 4], ].Tests
CSharpGeneratedSourceCompilesTests.TypelessLists_Compilebuilds the issue's repro withdotnet build, plus an array, a jagged table and an empty return, against a driver that reads each one back.The test declares
using System.Collections.Genericitself. Alist<T>that doesn't bring in its own using is #334, so it's left out of this PR.Generated by Claude Code