dotnet/roslyn

Duplicate (confusing) CS0455 error

开放

#5,053 创建于 2015年9月7日

 (0 条评论) (0 个反应) (0 位负责人)C# (4,257 个派生)batch import
Area-CompilersBugConcept-Diagnostic Clarityhelp wanted

仓库指标

星标
 (20,414 个星标)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

using System;

public abstract class ThingWithOrganizationId
{
    public Guid OrganizationId;
}

public class Thing : ThingWithOrganizationId
{
}

public abstract class BaseService<TConstraint, U> 
{
    public abstract void Save<T> (T newThing) where T : struct, TConstraint;
}

public class DerivedService:BaseService<Thing, X>
{
    public override void Save<TThing>(TThing newThing)
    {
        Console.WriteLine(newThing.OrganizationId);
    }

    static void Main ()
    {
    }
}

Roslyn csc produces following errors (24,31): error CS0455: Type parameter 'TThing' inherits conflicting constraints 'Thing' and 'ValueType' (24,31): error CS0455: Type parameter 'TThing' inherits conflicting constraints 'ValueType' and 'struct'

It should print something like this instead (24,31): error CS0455: Type parameter 'TThing' inherits conflicting constraints 'Thing' and 'struct'

贡献者指南