roslyn: Xmldoc with or similar fails to compile

Visual Studio 2019 RC (csc.exe version 3.0.19.12206 (ec366687)):

Steps to Reproduce:

Write this code. Note that Visual Studio helps you complete the <see cref...>. Enable XML documentation file and enable all warnings as errors.

using System;
namespace Repro2
{
    /// <summary/>
    public class Class1
    {
        void Foo<T>(T t) where T : class { }
        void Foo<T>(T? t) where T : struct { }

        /// <summary>
        /// See <see cref="Foo{T}(T?)"/>
        /// </summary>
        void Bar() { }
    }
}

Expected Behavior: It works.

Actual Behavior: It fails with CS1580 Invalid type for parameter T? in XML comment cref attribute: ‘Foo{T}(T?)’

If you change it to <see cref="Foo{T}(Nullable{T})"/> it works, but Visual Studio will now nag you to change it back to the version that doesn’t :p.

This is a regression; both syntaxes worked in Visual Studio 2017. The old compiler produced the following in the document file:

<see cref="M:Repro2.Class1.Foo``1(System.Nullable{``0})"/>

The new one produces:

<see cref="M:Repro2.Class1.Foo``1(``0)"/>

(and warns/fails if warnings as errors is enabled.)

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 2
  • Comments: 17 (13 by maintainers)

Most upvoted comments

I found a minimal reproducer. It seems that having a LangVersion < 8 is key.

Project.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>library</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <LangVersion>7.3</LangVersion>
    <DocumentationFile>ConsoleApp11.xml</DocumentationFile>
  </PropertyGroup>
</Project>

Program.cs

/// <summary>
/// Something about C
/// </summary>
public class C
{
    // warning CS1580: Invalid type for parameter T? in XML comment cref attribute: 'M{T}(T?)'
    /// <summary>Something about <see cref="M{T}(T?)" /></summary>
    public static void M<T>(T? t) where T : struct
    {
    }
}