Skip to content

Claude/fix issue 557 char string default param#1255

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

Claude/fix issue 557 char string default param#1255
GrahamTheCoder wants to merge 9 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
@GrahamTheCoder GrahamTheCoder force-pushed the claude/fix-issue-557-char-string-default-param branch 2 times, most recently from 49accae to eca463f Compare April 18, 2026 16:00
@GrahamTheCoder GrahamTheCoder marked this pull request as ready for review April 19, 2026 14:00
// For named constant references (e.g. DlM or Module.DlM), build a member access expression.
// Strip VB's "Global." prefix (VB global namespace qualifier, has no C# identifier equivalent).
// Annotate for simplification so Roslyn reduces e.g. TestModule.DlM → DlM within TestModule.
var parts = defaultValueNode.ToString().Trim().Split('.');
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.

Reinventing the wheel

// Annotate for simplification so Roslyn reduces e.g. TestModule.DlM → DlM within TestModule.
var parts = defaultValueNode.ToString().Trim().Split('.');
if (parts.Length > 1 && parts[0] == "Global") parts = parts.Skip(1).ToArray();
return ValidSyntaxFactory.MemberAccess(parts).WithAdditionalAnnotations(Simplifier.Annotation);
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.

The Simplifier.Annotation should already be added in the simplification pass

claude added 8 commits April 19, 2026 14:32
…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
…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
…g coalesce (strip VB Global prefix, add Simplifier annotation)
…Split('.')

Handle IdentifierNameSyntax, MemberAccessExpressionSyntax, and QualifiedNameSyntax
(which appears for Global.X references in default value context). Also remove
unnecessary Simplifier.Annotation since simplification is applied automatically
in a second phase.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
@GrahamTheCoder GrahamTheCoder force-pushed the claude/fix-issue-557-char-string-default-param branch from cc3c0d1 to 5c8966e Compare April 19, 2026 14:34
Replace the hand-rolled VbNameExprToCsExpr/BuildCharExpressionFromVbSyntax
static helpers with a call to the existing expression visitor
(_triviaConvertingExpressionVisitor) via AcceptAsync. This handles all
VB expression types uniformly without a verbose manual switch.

https://claude.ai/code/session_01AkwUvu3XuCdj3D4axoX4UX
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