www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Bug? package attribute half working on child packages.

reply Jeremie Pelletier <jeremiep gmail.com> writes:
I don't know if it's really a bug, but the package protection attribute seems
to have a different semantic in the current packages than in nested packages.

For example, say you have the module test which declares the following:
---
module test.Foo;

package uint myVar;
package class MyClass {}

package void MyFunc();

class Foo {
    package void MyFoo();
}
---

All declarations are accessible from any module in the test package, but if you
try and access them from a child package, say test.somepackage.Foo, then only
myVar and MyClass are accessible, both MyFunc and Foo.MyFoo says they aren't
accessible from test.somepackage.Foo.

I'm using the latest DMD version 2.
Mar 15 2009
next sibling parent reply Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Sun, Mar 15, 2009 at 5:55 PM, Jeremie Pelletier <jeremiep gmail.com> wro=
te:
 I don't know if it's really a bug, but the package protection attribute s=

ckages.
 For example, say you have the module test which declares the following:
 ---
 module test.Foo;

 package uint myVar;
 package class MyClass {}

 package void MyFunc();

 class Foo {
 =A0 =A0package void MyFoo();
 }
 ---

 All declarations are accessible from any module in the test package, but =

then only myVar and MyClass are accessible, both MyFunc and Foo.MyFoo says = they aren't accessible from test.somepackage.Foo.
 I'm using the latest DMD version 2.

http://d.puremagic.com/issues/show_bug.cgi?id=3D2529 Feel free to comment or vote.
Mar 15 2009
parent Daniel Keep <daniel.keep.lists gmail.com> writes:
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit



Jarrett Billingsley wrote:
 On Sun, Mar 15, 2009 at 5:55 PM, Jeremie Pelletier <jeremiep gmail.com> wrote:
 I don't know if it's really a bug, but the package protection attribute seems
to have a different semantic in the current packages than in nested packages.

 For example, say you have the module test which declares the following:
 ---
 module test.Foo;

 package uint myVar;
 package class MyClass {}

 package void MyFunc();

 class Foo {
    package void MyFoo();
 }
 ---

 All declarations are accessible from any module in the test package, but if
you try and access them from a child package, say test.somepackage.Foo, then
only myVar and MyClass are accessible, both MyFunc and Foo.MyFoo says they
aren't accessible from test.somepackage.Foo.

 I'm using the latest DMD version 2.

http://d.puremagic.com/issues/show_bug.cgi?id=2529 Feel free to comment or vote.

A quick poke in the source code reveals a hasPackageAccess function in access.c. Haven't tried this, but maybe the attached patch (made against the 1.041 release) will get the desired behaviour; I just quickly changed it to search not just the scope's package, but also its ancestors. -- Daniel
Mar 15 2009
prev sibling parent Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Sun, Mar 15, 2009 at 7:53 PM, Daniel Keep
<daniel.keep.lists gmail.com> wrote:
 Jarrett Billingsley wrote:
 On Sun, Mar 15, 2009 at 5:55 PM, Jeremie Pelletier <jeremiep gmail.com> =


 I don't know if it's really a bug, but the package protection attribute=



packages.
 For example, say you have the module test which declares the following:
 ---
 module test.Foo;

 package uint myVar;
 package class MyClass {}

 package void MyFunc();

 class Foo {
 =A0 =A0package void MyFoo();
 }
 ---

 All declarations are accessible from any module in the test package, bu=



, then only myVar and MyClass are accessible, both MyFunc and Foo.MyFoo say= s they aren't accessible from test.somepackage.Foo.
 I'm using the latest DMD version 2.

http://d.puremagic.com/issues/show_bug.cgi?id=3D2529 Feel free to comment or vote.

A quick poke in the source code reveals a hasPackageAccess function in access.c. =A0Haven't tried this, but maybe the attached patch (made against the 1.041 release) will get the desired behaviour; I just quickly changed it to search not just the scope's package, but also its ancestors. =A0-- Daniel --- access.c =A0 =A02009-03-05 01:56:46.000000000 +1100 +++ access.c =A0 =A02009-03-16 10:47:56.187500000 +1100 -305,12 +305,21 =A0 =A0 =A0 =A0printf("\tthis is in package '%s'\n", s->toChars()); =A0#endif - =A0 =A0if (s && s =3D=3D sc->module->parent) + =A0 =A0if (s) =A0 =A0 { -#if LOG - =A0 =A0 =A0 printf("\ts is in same package as sc\n"); -#endif - =A0 =A0 =A0 return 1; + =A0 =A0 =A0 =A0Dsymbol scp =3D sc->module->parent; + =A0 =A0 =A0 =A0for (Dsymbol scp =3D sc->module->parent; + =A0 =A0 =A0 =A0 =A0 =A0 scp && scp->isPackage() && !scp->isModule(); + =A0 =A0 =A0 =A0 =A0 =A0 scp =3D scp->parent) + =A0 =A0 =A0 =A0{ + =A0 =A0 =A0 =A0 =A0 =A0if (s && s =3D=3D scp) + =A0 =A0 =A0 =A0 =A0 =A0{ +#if LOG + =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf("\ts is in same package as or ancest=

 +#endif
 + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return 1;
 + =A0 =A0 =A0 =A0 =A0 =A0}
 + =A0 =A0 =A0 =A0}
 =A0 =A0 }

Oh! I suppose we can now.. give this a shot, and recompile the thing! :D
Mar 15 2009