Skip to content

[Bug]: Nullable Generic Type in CSharpType Returns Incorrect Type #3490

@ShivangiReja

Description

@ShivangiReja

Describe the bug

Encountered an issue with nullable generic types not being handled correctly by CSharpType.

Steps to Reproduce:

  1. Define a generic class and attempt to create a nullable generic type:

    private class Template<T> { }
    var genericType = new CSharpType(typeof(Template<>).GetGenericArguments()[0]).WithNullable(true); 
    // This returns T instead of T?
  2. Compare with a non-generic type:

    var intType = new CSharpType(typeof(int)).WithNullable(true); 
    // This returns int?

Expected Behavior:

The nullable generic type should return T?.

Actual Behavior:

The nullable generic type incorrectly returns T.

This discrepancy causes issues when working with nullable generic types, as the expected nullable type (T?) is not returned. Please investigate and resolve this inconsistency in CSharpType.

Note: After fixing this issue, uncomment this method -

// BuildAssertNotNullStruct(), // Currently, `_nullableT` returns `T` instead of `T?`. Tracking issue here: https://github.com/microsoft/typespec/issues/3490

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingemitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharp

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions