Skip to content

Honor ChainsToThis for zero-argument constructor delegation - #99

Merged
matt-edmondson merged 2 commits into
mainfrom
copilot/fix-chains-to-this-argument
Sep 13, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
copilot/fix-chains-to-this-argument

Conversation

Copilot AI commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

ConstructorTemplate previously emitted an initializer only when BaseParameters was non-empty, making ChainsToThis = true ineffective for zero-argument delegation. As a result, intended : this() chains were silently dropped and constructors fell back to implicit : base().

  • Initializer emission logic

    • Updated ConstructorTemplate.WriteInitialiserTo to emit an initializer when ChainsToThis is true, even if BaseParameters is empty.
    • Preserves existing behavior for base initializers when no parameters are supplied.
  • API contract/docs alignment

    • Clarified XML docs on BaseParameters and ChainsToThis to explicitly describe empty-argument behavior and : this() emission.
  • Coverage for missing case

    • Added a focused template rendering test for ChainsToThis = true with empty BaseParameters, asserting : this() is produced.
new ConstructorTemplate
{
    Name = "Widget",
    Keywords = { "public" },
    Parameters = { new ParameterTemplate { Type = "int", Name = "count" } },
    ChainsToThis = true,
}

Now renders:

public Widget(int count)
    : this() { }

Co-authored-by: matt-edmondson <19528727+matt-edmondson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ConstructorTemplate to handle zero-argument 'this()' delegation Honor ChainsToThis for zero-argument constructor delegation Sep 13, 2026
@matt-edmondson
matt-edmondson marked this pull request as ready for review September 13, 2026 13:05
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 08b1045 into main Sep 13, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the copilot/fix-chains-to-this-argument branch September 13, 2026 13:14
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.

ConstructorTemplate.ChainsToThis is silently ignored for a zero-argument : this()

2 participants