dotgnu-pnet
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pnet-developers] Re: Possible misinterpretation of 'protected internal'


From: Carl-Adam Brengesjo
Subject: [Pnet-developers] Re: Possible misinterpretation of 'protected internal'
Date: Tue, 07 Sep 2004 16:47:01 +0200
User-agent: Mozilla Thunderbird 0.6 (Windows/20040502)

I was a bit hasty to reply before so I thought I'd get some more info that supports my case...

I've tested it (see testcase below) on Microsoft's csc, and it does allow it. However, the ECMA (334) clearly states that:

"The intuitive meaning of protected internal is “access limited to this program [assembly] or types derived from the containing class”."

This reveals that it's a bug in csc rather than in cscc.
csc seems to interprent "protected internal" to allow access to the member in the same assembly as the derived class also. X is in the same assembly as B, and foo() is marked `internal', therefor allow access to foo() from B. Look on the testcase provided, X.SomeMethod() is allowed by csc, but not X.SomeMethod2(). This seems to me to be a clearly incorrect behaviour of csc as X does not belong to the same assembly as A.

But if you interprent "types derived from the containing class" to be types declared within a derived class to also be a derived class, it's a correct behaviour of csc, and a bug in cscc. Though I cannot interprent it as such.

Bottomline, the bug (#10311) is bogus; But it does apply to csc if not cscc. :-)

Anyways, good job finding bugs in M$ products ;)


PS. Dominique: Mailed wrong address before... see the pnet-developers list for my previous mail. DS.

------------------
test1.cs:
public class A
{
        protected internal void foo ()
        {
                Console.WriteLine("foo");
        }
}

test2.cs:
public class B : A
{
        static void Main()
        {
                new B();
        }
                        
        B()
        {
                X x = new X(this);
                x.SomeMethod();
                
                // both cscc and
                foo();
        }
                        
        private class X
        {
                private A owner;
                        
                public X(B owner)
                {
                        this.owner = owner;
                }
                
                // csc approves of this, so does cscc
                public void SomeMethod ()
                {
                        B myOwner = owner as B;
                        myOwner.foo ();
                }

                // csc fails this, so does cscc
                public void SomeMethod2()
                {
                        owner.foo ();
                }
        }
}

output:
$ cscc -g -o test.dll test1.cs -static
$ cscc -g -o test.exe test2.cs -ltest1.dll
test2.cs:29: called object is not a method or delegate
test2.cs:35: called object is not a method or delegate

>csc /T:library test1.cs
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

>csc test2.cs /r:test1.dll
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

test2.cs(35,4): error CS1540: Cannot access protected member 'A.foo()' via a qualifier of type 'A';
        the qualifier must be of type 'X' (or derived from it)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]