Skip to content

Write a null quoted DefaultValue as "" instead of throwing [patch] - #210

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/209-null-quoted-default
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/209-null-quoted-default

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

With DefaultValueIsQuoted set, HasDefaultValue is true whatever the value. A null DefaultValue therefore reached TemplateRendering.QuoteStringLiteral and threw a NullReferenceException after the declaration had been partly written, leaving void M}.

WriteDefaultValueTo now reads a null quoted value as empty, so it writes = "", as DefaultValue's docs already say an empty quoted value does. The doc comment now mentions null too.

Tests

  • New tests cover a parameter, a parameter inside a method in a class, a field and a property, each with DefaultValue = null!, DefaultValueIsQuoted = true. All four fail on main with the NRE and pass with the fix.
  • Full suite: 381 passed, 0 failed.

Fixes #209


Generated by Claude Code

With DefaultValueIsQuoted set, HasDefaultValue is true whatever the value, so a
null DefaultValue reached QuoteStringLiteral and threw NullReferenceException after
the declaration was partly written, leaving 'void M}'. A null is now read as empty,
which DefaultValue's docs already say writes "".

Fixes #209

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW2P5xiJJTm9Z4wJwcH
@sonarqubecloud

Copy link
Copy Markdown

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.

A null DefaultValue with DefaultValueIsQuoted = true throws NullReferenceException mid-declaration and leaves void M}

2 participants