Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Issue 8717 - Private and Protected should be accessible from within the same module. #1557

Merged
merged 1 commit into from

3 participants

@ghost

http://d.puremagic.com/issues/show_bug.cgi?id=8717

static if and static assert didn't have access of private and protected fields in the same module.

I'm not 100% sure whether this new check is correct.

src/access.c
@@ -219,7 +219,8 @@ void AggregateDeclaration::accessCheck(Loc loc, Scope *sc, Dsymbol *smember)
result = access2 >= PROTpublic ||
hasPrivateAccess(f) ||
isFriendOf(cdscope) ||
- (access2 == PROTpackage && hasPackageAccess(sc, this));
+ (access2 == PROTpackage && hasPackageAccess(sc, this) ||
+ getAccessModule() == sc->module);
@andralex Owner

one more indent please

@ghost
ghost added a note

Good eye, but the problem is I should have closed the paren on the line above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@MartinNowak MartinNowak commented on the diff
src/access.c
@@ -219,7 +219,8 @@ void AggregateDeclaration::accessCheck(Loc loc, Scope *sc, Dsymbol *smember)
result = access2 >= PROTpublic ||
hasPrivateAccess(f) ||
isFriendOf(cdscope) ||
- (access2 == PROTpackage && hasPackageAccess(sc, this));
+ (access2 == PROTpackage && hasPackageAccess(sc, this)) ||
+ getAccessModule() == sc->module;
@MartinNowak Collaborator

Do we still need hasPrivateAccess(f) and isFriendOf(cdscope) then?

@ghost
ghost added a note

I've been thinking of closing this down and doing a revamp of the whole thing. These access check functions are rather messy and there's copy-paste everywhere, it could really use a cleanup (and comments to go with it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@MartinNowak MartinNowak merged commit e7eff4d into D-Programming-Language:master
@MartinNowak
Collaborator

This commit MartinNowak/dmd@477cbd2 contains some protection refactorings and a bugfix of hasPackageAccess which might be a useful for you.
It was part of the overly ambitious pull request #727.

@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@ghost Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 26, 2013
  1. @drey08
This page is out of date. Refresh to see the latest.
Showing with 65 additions and 1 deletion.
  1. +2 −1  src/access.c
  2. +63 −0 test/compilable/test8717.d
View
3  src/access.c
@@ -219,7 +219,8 @@ void AggregateDeclaration::accessCheck(Loc loc, Scope *sc, Dsymbol *smember)
result = access2 >= PROTpublic ||
hasPrivateAccess(f) ||
isFriendOf(cdscope) ||
- (access2 == PROTpackage && hasPackageAccess(sc, this));
+ (access2 == PROTpackage && hasPackageAccess(sc, this)) ||
+ getAccessModule() == sc->module;
@MartinNowak Collaborator

Do we still need hasPrivateAccess(f) and isFriendOf(cdscope) then?

@ghost
ghost added a note

I've been thinking of closing this down and doing a revamp of the whole thing. These access check functions are rather messy and there's copy-paste everywhere, it could really use a cleanup (and comments to go with it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
#if LOG
printf("result1 = %d\n", result);
#endif
View
63 test/compilable/test8717.d
@@ -0,0 +1,63 @@
+module test8717;
+
+struct SPR
+{
+private:
+ enum e = 1;
+ immutable int ii = 1;
+ immutable static int sii = 1;
+ static int sf() { return 1; }
+ int f() const { return 1; }
+}
+
+static assert(SPR.e == 1);
+static assert(SPR.ii == 1);
+static assert(SPR.sii == 1);
+static assert(SPR.sf() == 1);
+static assert(SPR.init.e == 1);
+static assert(SPR.init.ii == 1);
+static assert(SPR.init.sii == 1);
+static assert(SPR.sf() == 1);
+static assert(SPR.init.f() == 1);
+
+static if(SPR.e != 1) { static assert(0); }
+static if(SPR.ii != 1) { static assert(0); }
+static if(SPR.sii != 1) { static assert(0); }
+static if(SPR.sf() != 1) { static assert(0); }
+static if(SPR.init.e != 1) { static assert(0); }
+static if(SPR.init.ii != 1) { static assert(0); }
+static if(SPR.init.sii != 1) { static assert(0); }
+static if(SPR.sf() != 1) { static assert(0); }
+static if(SPR.init.f() != 1) { static assert(0); }
+
+struct SPT
+{
+protected:
+ enum e = 1;
+ immutable int ii = 1;
+ immutable static int sii = 1;
+ static int sf() { return 1; }
+ int f() const { return 1; }
+}
+
+static assert(SPT.e == 1);
+static assert(SPT.ii == 1);
+static assert(SPT.sii == 1);
+static assert(SPT.sf() == 1);
+static assert(SPT.init.e == 1);
+static assert(SPT.init.ii == 1);
+static assert(SPT.init.sii == 1);
+static assert(SPT.sf() == 1);
+static assert(SPT.init.f() == 1);
+
+static if(SPT.e != 1) { static assert(0); }
+static if(SPT.ii != 1) { static assert(0); }
+static if(SPT.sii != 1) { static assert(0); }
+static if(SPT.sf() != 1) { static assert(0); }
+static if(SPT.init.e != 1) { static assert(0); }
+static if(SPT.init.ii != 1) { static assert(0); }
+static if(SPT.init.sii != 1) { static assert(0); }
+static if(SPT.sf() != 1) { static assert(0); }
+static if(SPT.init.f() != 1) { static assert(0); }
+
+void main() { }
Something went wrong with that request. Please try again.