Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 22, 2012 Pacikage level access broken? | ||||
---|---|---|---|---|
| ||||
I think I have a misunderstanding of how 'package' is suppose to work. How I understand it, you will give access to the directory, unlike private which will hide it outside of the same file. This problem comes up since a struct is declared inside a package (and even instantiated), however access to it is lacking. Here's my two sources. Using DMD v2.059 (Win32) --- t1.d module t1; import std.stdio; class Priv { //private by default int i; struct S { int s_i; } S s; } class Pack { package: int i; struct S { int s_i; } S s; } void test() { auto pr = new Priv(); auto pa = new Pack(); writefln("pr.i: %s\npr.s_i: %s\n", pr.i, pr.s.s_i); writefln("pa.i: %s\npa.s_i: %s\n", pa.i, pa.s.s_i); //okay, module level. pr.i = 10; pa.i = 10; pr.s.s_i = 10; pa.s.s_i = 10; } --- t2.d module t2; import std.stdio; import t1; //non-unittest void test(){ auto pr = new Priv(); auto pa = new Pack(); writefln("pr.i: %s\npr.s_i: %s\n", pr.i, pr.s.s_i); //should err, private writefln("pa.i: %s\npa.s_i: %s\n", pa.i, pa.s.s_i); //should pass? (Package level) //should fail, private pr.i = 10; pr.s.s_i = 10; //should pass, package pa.i = 10; pa.s.s_i = 10; } --- Errors t2.d(12): Error: undefined identifier 'i', did you mean 'import t1'? t2.d(12): Error: undefined identifier 's', did you mean 'import t1'? t2.d(19): Error: undefined identifier 'i', did you mean 'import t1'? t2.d(20): Error: undefined identifier 's', did you mean 'import t1'? The errors present refer to the 'pack' class, so it seems backwards. Did I miss something? |
April 22, 2012 Re: Pacikage level access broken? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Era Scarecrow | On Monday, April 23, 2012 01:21:21 Era Scarecrow wrote: > I think I have a misunderstanding of how 'package' is suppose to > work. How I understand it, you will give access to the directory, > unlike private which will hide it outside of the same file. 1. Package access is _very_ broken: http://d.puremagic.com/issues/show_bug.cgi?id=143 2. I'm not sure that your code is even using package properly. Note that t1 and t2 arguably don't _have_ a package. They're not pkg.t1 and pkg.t2, they're just straight t1 and t2. So, even if package were working properly, I'm not sure that t1 and t2 would ever be considered to be in the same package. - Jonathan M Davis |
April 22, 2012 Re: Package level access broken? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Sunday, 22 April 2012 at 23:32:40 UTC, Jonathan M Davis wrote: > 1. Package access is _very_ broken: > http://d.puremagic.com/issues/show_bug.cgi?id=143 Fun... So it's not just me... Guess for the 1-2 places I 'll need package level access instead I gotta either do public or get some getters (Was just hoping to ignore that). > 2. I'm not sure that your code is even using package properly. No, they may not be in a package specifically; I but with them being directory/hierarchy they should be in the package group. Anyways, thanks for the quick and easy response. |
April 23, 2012 Re: Pacikage level access broken? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Era Scarecrow | On 2012-04-23 01:21, Era Scarecrow wrote: > I think I have a misunderstanding of how 'package' is suppose to work. > How I understand it, you will give access to the directory, unlike > private which will hide it outside of the same file. > > This problem comes up since a struct is declared inside a package (and > even instantiated), however access to it is lacking. Here's my two > sources. Using DMD v2.059 (Win32) > > --- t1.d > module t1; > > import std.stdio; > > class Priv { //private by default > int i; > struct S { > int s_i; > } "public" is the default access level. -- /Jacob Carlborg |
April 23, 2012 Re: Pacikage level access broken? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Monday, 23 April 2012 at 06:19:12 UTC, Jacob Carlborg wrote:
> "public" is the default access level.
So it is... That explains why the tests came out backwards on the results.... Wasn't it private by default in C++? I honestly don't know sometimes.
|
April 23, 2012 Re: Pacikage level access broken? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Mon, 23 Apr 2012 01:32:25 +0200, Jonathan M Davis <jmdavisProg@gmx.com> wrote: > On Monday, April 23, 2012 01:21:21 Era Scarecrow wrote: >> I think I have a misunderstanding of how 'package' is suppose to >> work. How I understand it, you will give access to the directory, >> unlike private which will hide it outside of the same file. > > 1. Package access is _very_ broken: > http://d.puremagic.com/issues/show_bug.cgi?id=143 > > 2. I'm not sure that your code is even using package properly. Note that t1 > and t2 arguably don't _have_ a package. They're not pkg.t1 and pkg.t2, they're > just straight t1 and t2. So, even if package were working properly, I'm not > sure that t1 and t2 would ever be considered to be in the same package. > > - Jonathan M Davis These things comes up quite often: "shared is broken", "alias this is broken", "package is broken", "scope is broken", "X is broken", "Y is broken". I believe this should be addressed in a very visible place to avoid getting the impression that everything in D is "horribly broken". The frontpage on the wiki could list incomplete features that you should steer away to avoid hitting compiler bugs. http://prowiki.org/wiki4d/wiki.cgi?LanguageDevel#DMDCompilerStability includes some of these issues, but it's hidden and doesn't show it in an easy to grasp way for beginners. It shouldn't be necessary to be following the development of D intimately to know what features are implemented and considered production ready. I think it gives a better impression to list the features still under development than to let (new) users hit bugs within the first hours (read: minutes) of hacking around. |
April 23, 2012 Re: Pacikage level access broken? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Era Scarecrow | On 2012-04-23 10:26, Era Scarecrow wrote: > On Monday, 23 April 2012 at 06:19:12 UTC, Jacob Carlborg wrote: >> "public" is the default access level. > > So it is... That explains why the tests came out backwards on the > results.... Wasn't it private by default in C++? I honestly don't know > sometimes. I think so. If you use "class" it's private by default. If use "struct" it's public by default. That's basically the only difference between "class" and "struct" in C++, if I recall correctly. -- /Jacob Carlborg |
April 23, 2012 Re: Pacikage level access broken? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Monday, April 23, 2012 13:42:36 Jacob Carlborg wrote:
> On 2012-04-23 10:26, Era Scarecrow wrote:
> > On Monday, 23 April 2012 at 06:19:12 UTC, Jacob Carlborg wrote:
> >> "public" is the default access level.
> >
> > So it is... That explains why the tests came out backwards on the results.... Wasn't it private by default in C++? I honestly don't know sometimes.
>
> I think so. If you use "class" it's private by default. If use "struct" it's public by default. That's basically the only difference between "class" and "struct" in C++, if I recall correctly.
That's correct. In C++, struct and class are identical except that a class' members are private by default and a struct's members are public by default.
- Jonathan M Davis
|
April 24, 2012 Re: Pacikage level access broken? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On 04/23/2012 07:43 PM, Jonathan M Davis wrote:
> On Monday, April 23, 2012 13:42:36 Jacob Carlborg wrote:
>> On 2012-04-23 10:26, Era Scarecrow wrote:
>>> On Monday, 23 April 2012 at 06:19:12 UTC, Jacob Carlborg wrote:
>>>> "public" is the default access level.
>>>
>>> So it is... That explains why the tests came out backwards on the
>>> results.... Wasn't it private by default in C++? I honestly don't know
>>> sometimes.
>>
>> I think so. If you use "class" it's private by default. If use "struct"
>> it's public by default. That's basically the only difference between
>> "class" and "struct" in C++, if I recall correctly.
>
> That's correct. In C++, struct and class are identical except that a class'
> members are private by default and a struct's members are public by default.
>
> - Jonathan M Davis
The same holds for the default base class access.
|
Copyright © 1999-2021 by the D Language Foundation