[Mono-list] [PATCH] "protected internal" semantics
Jaroslaw Kowalski
jarek@atm.com.pl
Sat, 14 Dec 2002 19:38:17 +0100
This is a multi-part message in MIME format.
------=_NextPart_000_000B_01C2A3A8.59A56540
Content-Type: text/plain;
charset="iso-8859-2"
Content-Transfer-Encoding: 7bit
Hi!
Today I've reported an MCS error where it wasn't possible to override
"protected internal" method with method declared as "protected" in another
assembly.
Here's my attempt to fix it: I've added some conditions in "decl.cs" (patch
included) and some mini test to check this functionality (second and fourth
compilations should fail under both mcs and csc)
Can you please verify the patch and commit if it's ok (I'm using read-only
CVS access)
Jarek
PS. Yes, the tests are very ugly but I couldn't come up with anything simple
to do the job.
------=_NextPart_000_000B_01C2A3A8.59A56540
Content-Type: application/octet-stream;
name="protected_internal.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="protected_internal.patch"
Index: ChangeLog=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mcs/mcs/ChangeLog,v=0A=
retrieving revision 1.915=0A=
diff -u -r1.915 ChangeLog=0A=
--- ChangeLog 13 Dec 2002 09:46:54 -0000 1.915=0A=
+++ ChangeLog 14 Dec 2002 18:29:08 -0000=0A=
@@ -1,3 +1,8 @@=0A=
+2002-12-14 Jaroslaw Kowalski <jarek@atm.com.pl>=0A=
+=0A=
+ * decl.cs: Added special case to allow overrides on "protected=0A=
+ internal" methods=0A=
+=0A=
2002-12-13 Gonzalo Paniagua Javier <gonzalo@ximian.com>=0A=
=0A=
* namespace.cs: fixed bug #35489.=0A=
Index: decl.cs=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0A=
RCS file: /mono/mcs/mcs/decl.cs,v=0A=
retrieving revision 1.47=0A=
diff -u -r1.47 decl.cs=0A=
--- decl.cs 27 Nov 2002 17:17:19 -0000 1.47=0A=
+++ decl.cs 14 Dec 2002 18:29:09 -0000=0A=
@@ -94,16 +94,67 @@=0A=
"' because it is sealed.");=0A=
ok =3D false;=0A=
}=0A=
-=0A=
//=0A=
// Check that the permissions are not being changed=0A=
//=0A=
MethodAttributes thisp =3D my_attrs & =
MethodAttributes.MemberAccessMask;=0A=
MethodAttributes parentp =3D mb.Attributes & =
MethodAttributes.MemberAccessMask;=0A=
=0A=
- if (thisp !=3D parentp){=0A=
- Error_CannotChangeAccessModifiers (parent, mb, name);=0A=
- ok =3D false;=0A=
+ //=0A=
+ // special case for "protected internal"=0A=
+ //=0A=
+=0A=
+ if ((parentp & MethodAttributes.FamORAssem) =3D=3D =
MethodAttributes.FamORAssem)=0A=
+ {=0A=
+ // when overriding protected internal, the method can be declared=0A=
+ // protected internal only within the same assembly=0A=
+=0A=
+ if ((thisp & MethodAttributes.FamORAssem) =3D=3D =
MethodAttributes.FamORAssem)=0A=
+ {=0A=
+ if (parent.TypeBuilder.Assembly !=3D mb.DeclaringType.Assembly)=0A=
+ {=0A=
+ // assemblies differ - report an error=0A=
+ =0A=
+ Error_CannotChangeAccessModifiers (parent, mb, name);=0A=
+ ok =3D false;=0A=
+ }=0A=
+ else if (thisp !=3D parentp)=0A=
+ {=0A=
+ // same assembly, but other attributes differ - report an error=0A=
+=0A=
+ Error_CannotChangeAccessModifiers (parent, mb, name);=0A=
+ ok =3D false;=0A=
+ };=0A=
+ }=0A=
+ else if ((thisp & MethodAttributes.Family) !=3D =
MethodAttributes.Family)=0A=
+ {=0A=
+ // if it's not "protected internal", it must be "protected"=0A=
+=0A=
+ Error_CannotChangeAccessModifiers (parent, mb, name);=0A=
+ ok =3D false;=0A=
+ }=0A=
+ else if (parent.TypeBuilder.Assembly =3D=3D =
mb.DeclaringType.Assembly)=0A=
+ {=0A=
+ // protected within the same assembly - an error=0A=
+ Error_CannotChangeAccessModifiers (parent, mb, name);=0A=
+ ok =3D false;=0A=
+ }=0A=
+=0A=
+ else if ((thisp & ~(MethodAttributes.Family | =
MethodAttributes.FamORAssem))=0A=
+ !=3D (parentp & ~(MethodAttributes.Family | =
MethodAttributes.FamORAssem)))=0A=
+ {=0A=
+ // protected ok, but other attributes differ - report an error=0A=
+=0A=
+ Error_CannotChangeAccessModifiers (parent, mb, name);=0A=
+ ok =3D false;=0A=
+ }=0A=
+ }=0A=
+ else=0A=
+ {=0A=
+ if (thisp !=3D parentp){=0A=
+ Error_CannotChangeAccessModifiers (parent, mb, name);=0A=
+ ok =3D false;=0A=
+ }=0A=
}=0A=
}=0A=
=0A=
------=_NextPart_000_000B_01C2A3A8.59A56540
Content-Type: application/x-gzip;
name="test.tar.gz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="test.tar.gz"
H4sIANp2+z0AA+2YTW/CIBiAe7XJ/gNHd1GgtCTutO28227LDvQjhqQWA2iyLP730dZZjR9zM223
+T4HMeUtNMXn5UWbGTv22gVjhjkPXYtdi3faNR7mIY8iHgTld4LDiHkobPm5KhbGCo2QN1OFOhX3
Vf8fxZbrH+NRYtqbw60njhg7vv6cf64/pVHk4gmjoYdwe4/UcOXrP1/EuUxQkgtj0ANBE3Tvv/uD
uVY2S2yWIrXMtJZphpZKpujZ/VzI8NYfuJiVv/L7fnzgQmr/Sa/+E4K3/GeV/+4S+N8Bu/7jff9l
YTNdiBwSwb+k8l/06z/l0cb/gNF6/yfgfxes/RexsVokdp0IjuWATdh2DrhzofUo7lVa11SdT0IW
Qxcti+nLKxJ6appk4R+e9fG71QdknYup/e+3/g9wU//j8nq5/4P/nfDL/T+z+oBE8FMq/8uPUTJL
W5qj9J+Hx///oYQ19X95FiDUAf53QWISNC5UrqYKje0kl7EW+g1VO8KNf6yX7PfqibsnzfPtuPjA
KAfj6vH6fhfXyMZ/aVub42v/m/M/q+p/iimc/zvhlP8n9T/T/jPlB/cBAAAAAAAAAAAAoEU+ABkc
+oQAKAAA
------=_NextPart_000_000B_01C2A3A8.59A56540--