Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected Interface in Class base list #3230

Open
bernd5 opened this issue Jul 8, 2024 · 1 comment
Open

Unexpected Interface in Class base list #3230

bernd5 opened this issue Jul 8, 2024 · 1 comment
Labels

Comments

@bernd5
Copy link

bernd5 commented Jul 8, 2024

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.

@bernd5 bernd5 added the Bug label Jul 8, 2024
@dgrunwald
Copy link
Member

Huh, so SubF's base class list has visibility to the protected SubF.ISubFoo, but not to the protected SubF.IFoo/F.IFoo.
That is surprising.
The old (pre-roslyn) csc also rejects your original code.

I think we can only try to detect this situation and suppress the base list entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants