Skip to content

Bug in example in 13.5.4, namespaces/using static directives #635

Closed
@RexJaeschke

Description

@RexJaeschke

The final example in this section has a bug:

namespace N1 
{
    static class A 
    {
        public static void M(string s){}
    }

    static class B : A
    {
        public static void M2(string s){}
    }
}

namespace N2
{
    using static N1.B;

    class C
    {
        void N()
        {
            M2("B");      // OK, calls B.M2
            M("C");       // Error. M unknown 
        }
    }
}

Based on the comment near the end, the intent is that an error results based on M being unknown. However, the compiler doesn't get that far. Instead, it complains about the declaration

static class B : A

According to 14.2.2.4.1, a static class (such as A) cannot be used as a base class, and a static class (such as B) cannot derive from anything other than object. So, the program is ill-formed.

Blame says this example was added in July 2021, in V6.

I didn't see an obvious workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugThe Standard does not describe the language as intended or implemented

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions