Skip to content

Fail to compile C# 14.0 extension with interface constraint using implicit additional type parameters #78472

@xoofx

Description

@xoofx

Hey, ☺️

I'm playing with the C# 14.0 extension feature and love it! While experimenting I discovered the following issue:

    public struct AStruct<K, V> : AStruct<K, V>.AnInterface<AStruct<K, V>>
    {
        public interface AnInterface<out T>
        {
        }
    }

    // Compiles fine
    public static void Ok<T, K, V>(T @this) where T : AStruct<K, V>.AnInterface<T>
    {
    }

    // CS9295 on @this
    extension<T, K, V>(T @this) where T: AStruct<K, V>.AnInterface<T>
    {
    }

And the @this parameter is getting flagged with:

Program.cs(67,26,67,31): error CS9295: The extended type 'T' must reference all the type parameters declared by the extension, but type parameter 'K' is not referenced.
Program.cs(67,26,67,31): error CS9295: The extended type 'T' must reference all the type parameters declared by the extension, but type parameter 'V' is not referenced.

I would believe that it is a scenario that should be supported. Thoughts?

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions