Skip to content

Unexpected Interface in Class base list #3230

Description

@bernd5

Steps to reproduce

Compile:

new F().Bar();
new SubF().Bar();


class F : F.IFoo
{
    protected interface IFoo
    {
        void Foo();
    }

    void IFoo.Foo()
    {
        System.Console.WriteLine("F");
    }

    public void Bar()
    {
        ((IFoo)this).Foo();
    }
}

class SubF : F, SubF.ISubFoo
{
    protected interface ISubFoo : F.IFoo { }

    void F.IFoo.Foo()
    {
        System.Console.WriteLine("SubF");
    }
}

Decompiled CSharp:

using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]

internal class F : F.IFoo
{
    protected interface IFoo
    {
        void Foo();
    }

    void IFoo.Foo()
    {
        Console.WriteLine("F");
    }

    public void Bar()
    {
        ((IFoo)this).Foo();
    }
}

internal class SubF : F, SubF.ISubFoo, F.IFoo //<-- F.IFoo is not implemented directly
{
    protected interface ISubFoo : IFoo
    {
    }

    void IFoo.Foo()
    {
        Console.WriteLine("SubF");
    }
}

The interface list of SubF contains an unexpected F.IFoo. This is invalid CSharp - it would not compile.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions