VB -> C#: omitted parentheses cause conversion failures in delegates and custom-event raise accessors

Open
#1,298 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
csharp, visualbasic
Domain
compilers

Research direction

Start in the DeclarationNodeVisitor.VisitDelegateStatement path, where a null parameter list reaches SyntaxFactory.DelegateDeclaration; supply an empty C# parameter list as ordinary methods already do. Then check how a parameterless RaiseEvent accessor is converted so that the On<EventName>() method is not dropped. Done when both VB inputs with and without parentheses produce identical C# output, matching the expected delegate lines.

Written by the indexing model from the issue text.

Description

VB -> C#
VB.Net input code
Public Delegate Sub Callback
Public Delegate Function Provider As Integer
Erroneous output
Cannot convert DelegateStatementSyntax, CONVERSION ERROR:
Value cannot be null. (Parameter 'parameterList')

at Microsoft.CodeAnalysis.CSharp.SyntaxFactory.DelegateDeclaration(...)
at ICSharpCode.CodeConverter.CSharp.DeclarationNodeVisitor.VisitDelegateStatement(...)
Expected output
public delegate void Callback();
public delegate int Provider();
Details
  • Product in use: VS extension, built locally from master.
  • Version in use: 10.0.1, local development build.
  • Did you see it working in a previous version, which? No.
  • Related to #1296: VB.NET permits parameterless delegate declarations without parentheses. Adding () after Callback or Provider avoids the failure, but both forms should convert identically.
  • The delegate visitor passes a null parameter list to the C# syntax factory when parentheses are omitted. Supplying an empty C# parameter list resolves the issue, consistent with the existing handling for ordinary methods and external declarations.
  • The same problem also affects a custom event's parameterless RaiseEvent accessor when declared without parentheses. In that case, the generated C# event is retained, but its corresponding On<EventName>() method is silently omitted.
Dominant language
C#
Stars
916
Forks
242
Avg merge
2d 15h
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from icsharpcode/CodeConverter

All issues in icsharpcode/CodeConverter

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.