Skip to content

default constraint of generic type is not generated #10526

@andriipatsula

Description

@andriipatsula

Example:

public abstract partial class A
{
    public abstract TResult? Accept<TResult>(int a);
}

public sealed partial class B : A
{
    public override TResult? Accept<TResult>(int a) where TResult : default { throw null; }
}

After roundtrip: source -> ISymbol-> SyntaxGenerator -> source:

public abstract partial class A
{
    public abstract TResult? Accept<TResult>(int a);
}
public sealed partial class B : A
{
    /// error CS0508: 'B.Accept<TResult>(int)': return type must be 'TResult' to match overridden member 'A.Accept<TResult>(int)'
    /// error CS0453: The type 'TResult' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'Nullable<T>'
    public override TResult? Accept<TResult>(int a) { throw null; }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions