Bug 257 – package vars accessible from sub-modules, package funcs not
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2006-07-18T16:57:17Z
Last change time
2017-11-02T11:31:50Z
Keywords
accepts-invalid, bootcamp
Assigned to
No Owner
Creator
Jarrett Billingsley
Comments
Comment #0 by jarrett.billingsley — 2006-07-18T16:57:17Z
-------- modules/mymod.d ----------
module modules.mymod;
package int foo;
package void bar()
{
}
-------- modules/level/test.d ----------
module modules.level.test;
import modules.mymod;
void f()
{
foo = 1;
bar();
}
----------------------------------------
Compiling those gives an error when trying to access bar() from test, but accessing foo is OK.
Moreover,
-------- modules/mymod2.d ----------
module modules.mymod2; // notice it's in the same package as mymod
import modules.mymod;
void f()
{
foo = 1;
bar();
}
--------------------------------------
Works, as expected, just fine.
If I'm reading the spec correctly, neither foo or bar() should be accessible from test, as only modules in the same package (i.e. other modules in the "modules" package; test is in "modules.level") should be able to access them.
I'm flagging this as accepts-invalid, as you can access foo, when I don't think you should.
Comment #1 by thomas-dloop — 2006-09-14T07:15:38Z
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
[email protected] schrieb am 2006-07-18:
> http://d.puremagic.com/issues/show_bug.cgi?id=257
> -------- modules/mymod.d ----------
>
> module modules.mymod;
>
> package int foo;
>
> package void bar()
> {
>
> }
>
> -------- modules/level/test.d ----------
>
> module modules.level.test;
>
> import modules.mymod;
>
> void f()
> {
> foo = 1;
> bar();
> }
>
> ----------------------------------------
>
> Compiling those gives an error when trying to access bar() from test, but
> accessing foo is OK.
>
> Moreover,
>
> -------- modules/mymod2.d ----------
>
> module modules.mymod2; // notice it's in the same package as mymod
>
> import modules.mymod;
>
> void f()
> {
> foo = 1;
> bar();
> }
>
> --------------------------------------
>
> Works, as expected, just fine.
>
> If I'm reading the spec correctly, neither foo or bar() should be accessible
> from test, as only modules in the same package (i.e. other modules in the
> "modules" package; test is in "modules.level") should be able to access them.
>
> I'm flagging this as accepts-invalid, as you can access foo, when I don't think
> you should.
Added to DStress as
http://dstress.kuehne.cn/nocompile/p/package_05_A.dhttp://dstress.kuehne.cn/nocompile/p/package_05_B.d
( http://dstress.kuehne.cn/addon/package_05_Z.d )
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFFCUaaLK5blCcjpWoRAjbbAKCSllSXmw7QFo2V3srH49gDTGtKswCfXdiN
BY+/ItsnTXzLkDtlG+WubnE=
=SNmH
-----END PGP SIGNATURE-----
Comment #2 by razvan.nitu1305 — 2017-11-02T11:31:50Z
(In reply to Jarrett Billingsley from comment #0)
> -------- modules/mymod.d ----------
>
> module modules.mymod;
>
> package int foo;
>
> package void bar()
> {
>
> }
>
> -------- modules/level/test.d ----------
>
> module modules.level.test;
>
> import modules.mymod;
>
> void f()
> {
> foo = 1;
> bar();
> }
>
> ----------------------------------------
>
> Compiling those gives an error when trying to access bar() from test, but
> accessing foo is OK.
>
> Moreover,
>
> -------- modules/mymod2.d ----------
>
> module modules.mymod2; // notice it's in the same package as mymod
>
> import modules.mymod;
>
> void f()
> {
> foo = 1;
> bar();
> }
>
> --------------------------------------
>
> Works, as expected, just fine.
>
> If I'm reading the spec correctly, neither foo or bar() should be accessible
> from test, as only modules in the same package (i.e. other modules in the
> "modules" package; test is in "modules.level") should be able to access them.
>
> I'm flagging this as accepts-invalid, as you can access foo, when I don't
> think you should.
Compiling both examples on Ubuntu 16.04 and Windows (via wine) with git HEAD results in successful compilation as it should. modules/level/test is a subpackage of the package modules and is considered to be in the same package as mymod. Therefore, both package members bar and foo should be accesible and they are. Closing as fixed.