3

The following code does not compile using VS 2013:

public class Base<T>
{
}

public class Derived : Base<Derived.Nested.Inside>
{
    public class Nested
    {
        public class Inside
        {
        }
    }
}

The compiler says:

Circular base class dependency involving 'Demo.Derived' and 'Demo.Derived.Nested'

The same code compiles okay using VS 2015.

I don't see any circular base class dependency. Is this a VS 2013 bug?

Peter Perot
  • 1,003
  • 1
  • 10
  • 15
  • 1
    How is that not a circular base class dependency? You are inheriting from a type that you have set to the class you are extending. The exception is correct. – Stephen Brickner Nov 11 '15 at 11:34
  • Nope. I'm inheriting from `Base` and set the type parameter `T` to `Derived.Nested.Inside`. If you were right deriving from `Base` should also yield an error, but this is not the case. And in VS 2015 my code compiles okay. – Peter Perot Nov 11 '15 at 12:21
  • Right you are basically inheriting from the class you are in. Hence, circular dependency. Consider this: MyClass : MyClass , that is basically what you are doing. A nested type is still part of that type. – Stephen Brickner Nov 11 '15 at 12:23
  • IOW: `Derived : Derived.Nested.Inside` does not compile, and this is okay. But `Derived : Base` is something different. – Peter Perot Nov 11 '15 at 12:24
  • Can you explain why `public class Derived : Base` compiles, but putting one more level of nesting in (`Derived.Nested.Inside`) does not compile? – Peter Perot Nov 11 '15 at 12:26
  • 2
    Well, if it compiles in VS2015 and it doesn't in VS2013 then its a bug in VS2013; I see no reason why this should be illegal. I seem to recall Eric Lippert commenting that the circular dependency detection logic in Roslyn was thoroughly revised and some existing false positives in previous versions of the compiler were fixed but I can't find where I read it. – InBetween Nov 11 '15 at 13:51

0 Answers0