Skip to content

Commit 78a1610

Browse files
Fix VbNameExpander corrupting open generic types like GetType(Nullable(Of))
Roslyn's Simplifier.Expand replaces missing type arguments (open generics like Nullable(Of)) with an error type fallback (Object), causing GetType(Nullable(Of)) to incorrectly convert to typeof(object) instead of typeof(Nullable<>). Guard against this in NameCanBeExpanded by detecting GenericNameSyntax nodes with missing type arguments and skipping expansion, preserving the open generic form so the conversion visitors can correctly emit OmittedTypeArgument. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4310d6e commit 78a1610

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CodeConverter/CSharp/VbNameExpander.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ private static bool NameCanBeExpanded(SyntaxNode node)
110110
if (node.Parent is NameColonEqualsSyntax || node.Parent is NamedFieldInitializerSyntax) return false;
111111
// Workaround roslyn bug where it duplicates the inferred name
112112
if (node.Parent is InferredFieldInitializerSyntax) return false;
113+
// Roslyn's Simplifier.Expand corrupts open generic type arguments (e.g. Nullable(Of) in GetType(Nullable(Of)))
114+
// by replacing them with the error type fallback (Object). Prevent expansion so the missing type arg is preserved.
115+
if (node is GenericNameSyntax gns && gns.TypeArgumentList.Arguments.Any(a => a is IdentifierNameSyntax id && id.Identifier.IsMissing)) return false;
113116
return true;
114117
}
115118

Tests/CSharp/ExpressionTests/OmittedTypeArgumentTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Return type.IsGenericType AndAlso type.GetGenericTypeDefinition() Is GetType(Nul
1616
End Function
1717
End Class", @"using System;
1818
19-
public class Test
19+
public partial class Test
2020
{
21-
public bool IsNullable(Type type)
21+
public bool IsNullable(Type @type)
2222
{
2323
return type.IsGenericType && ReferenceEquals(type.GetGenericTypeDefinition(), typeof(Nullable<>));
2424
}

0 commit comments

Comments
 (0)