Pacikage level access broken?

Era Scarecrow rtcvb32 at yahoo.com
Sun Apr 22 16:21:21 PDT 2012


  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?


More information about the Digitalmars-d-learn mailing list