Skip to content

Claude/fix issue 557 char string default param#1255

Draft
GrahamTheCoder wants to merge 6 commits intoicsharpcode:masterfrom
GrahamTheCoder:claude/fix-issue-557-char-string-default-param
Draft

Claude/fix issue 557 char string default param#1255
GrahamTheCoder wants to merge 6 commits intoicsharpcode:masterfrom
GrahamTheCoder:claude/fix-issue-557-char-string-default-param

Conversation

@GrahamTheCoder
Copy link
Copy Markdown
Member

Fixes #557


// Replace the default value with null
updatedParams[i] = csParam.WithDefault(
CS.SyntaxFactory.EqualsValueClause(ValidSyntaxFactory.NullExpression));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This pattern of mutating previously set values is not recommended. We should set it to be null at the point of creation, then separately here we should add the null coalesce and use comments to mention the other place. This is obviously also not ideal, but a conceptual dependency from a distance is generally better than a concrete one where someone else might intercept it in between in the same style otherwise.

@GrahamTheCoder GrahamTheCoder marked this pull request as draft April 16, 2026 23:06
claude added 6 commits April 16, 2026 23:31
…s null + null-coalescing assignment

When VB has Optional ByVal strParam As String = charConst, C# can't use
a char literal as a string default. Replace the default with null and
prepend strParam = strParam ?? charConst.ToString() in the method body.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
…r string parameter

Two tests cover the fix for converting VB Optional string parameters with
char default values: one using a const reference and one using an inline
char literal.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
…ts.cs

The TestOverridableAutoPropertyBackingFieldAccessAsync test (issue icsharpcode#827)
was mistakenly added to this branch, which only contains the fix for
issue icsharpcode#557. The icsharpcode#827 fix code is in a separate PR (icsharpcode#1252) and is not
present here, so the test would always fail.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
…lt for String params

ExplicitDefaultValue is normalized to the parameter's declared type, so
checking `ExplicitDefaultValue is not char` was always true for String params.
Instead, retrieve the VB syntax default expression and check its actual type
via the semantic model.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
…ix method

VisitParameter now sets the default to null directly when it detects a
char-typed default for a string parameter, rather than converting to a
char expression that FixCharDefaultsForStringParams would later replace.

FixCharDefaultsForStringParams now reconstructs the char expression from
the VB syntax node via BuildCharExpressionFromVbSyntax, removing the
previously-set-then-overwritten value pattern.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
… in else branch

The outer 'if (node.Default != null)' block already declares 'defaultValue' on
line 449. The branch's new else-branch code was incorrectly redeclaring it, causing
CS0136: A local variable named 'defaultValue' is already defined in this scope.
Fix: remove the redundant declaration in the else branch and reuse the existing one.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
@GrahamTheCoder GrahamTheCoder force-pushed the claude/fix-issue-557-char-string-default-param branch from 43e33b4 to c055eee Compare April 16, 2026 23:36
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.

VB -> C#: You can’t assign char to string directly

2 participants