roslyn: [bug] xml docs generics+`inheritdoc`+`typeparamref`

There is a bug in the displayed XML documentation regarding generics+inheritdoc+typeparamref that is currently reproduceable in both Visual Studio and Visual Studio Code.

Consider the following top-level program in .NET 5+

Test<int> a = new();
var b = a.Clone();

public class Test<T> : ICloneable<Test<T>>
{
	/// <inheritdoc/>
	public Test<T> Clone() => new();
}

/// <summary>A type that has clonable instances.</summary>
/// <typeparam name="T">The type of instances that can be cloned.</typeparam>
public interface ICloneable<T>
{
	/// <summary>Clones a <typeparamref name="T"/>.</summary>
	/// <returns>A clone of the <typeparamref name="T"/>.</returns>
	public T Clone();
}

Now hover over the Clone method on line 2 where we have var b = a.Clone();.

Screenshot from Visual Studio: image

Screenshot from Visual Studio Code: image

The “T” shown in the pop-up XML comments is not correct. It is showing the “T” relative to the Test<T> type rather than the “T” relative to the ICloneable<T> type. In other words, the pop-up is saying

Clones a int. Returns: A clone of the int.

when it should say

Clones a Test<int>. Returns: A clone of the Test<int>.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (11 by maintainers)

Most upvoted comments

@ZacharyPatten No need to do it on your end. I confirmed it locally. Finally can reproduce:

image

Thanks @sharwell for pointing this out!

I’ll open a new issue for it.