Skip to content

Commit 73b503c

Browse files
committed
Fix Issue 15896 - private ignored when import bindings are used
1 parent 4d698db commit 73b503c

4 files changed

Lines changed: 30 additions & 5 deletions

File tree

src/ddmd/dimport.d

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module ddmd.dimport;
1313
import core.stdc.string;
1414
import core.stdc.stdio;
1515

16+
import ddmd.access;
1617
import ddmd.arraytypes;
1718
import ddmd.declaration;
1819
import ddmd.dmodule;
@@ -244,7 +245,7 @@ extern (C++) final class Import : Dsymbol
244245
if (mod)
245246
{
246247
// Modules need a list of each imported module
247-
//printf("%s imports %s\n", sc.module.toChars(), mod.toChars());
248+
//printf("%s imports %s\n", sc._module.toChars(), mod.toChars());
248249
sc._module.aimports.push(mod);
249250

250251
if (sc.explicitProtection)
@@ -295,10 +296,15 @@ extern (C++) final class Import : Dsymbol
295296
for (size_t i = 0; i < aliasdecls.dim; i++)
296297
{
297298
AliasDeclaration ad = aliasdecls[i];
298-
//printf("\tImport %s alias %s = %s, scope = %p\n", toPrettyChars(), aliases[i].toChars(), names[i].toChars(), ad._scope);
299-
if (mod.search(loc, names[i]))
299+
//printf("\tImport %s alias %s = %s, scope = %p\n", toPrettyChars(), aliasdecls[i].toChars(), names[i].toChars(), ad._scope);
300+
Dsymbol importedSymbol = mod.search(loc, names[i]);
301+
if (importedSymbol)
300302
{
301-
ad.semantic(sc);
303+
// BUGZILLA 15896 : if symbol is private then it shouldn't be accessed
304+
if(importedSymbol.prot().kind == PROTprivate)
305+
mod.error(loc, "member '%s' is private", names[i].toChars());
306+
else
307+
ad.semantic(sc);
302308
// If the import declaration is in non-root module,
303309
// analysis of the aliased symbol is deferred.
304310
// Therefore, don't see the ad.aliassym or ad.type here.
@@ -307,7 +313,9 @@ extern (C++) final class Import : Dsymbol
307313
{
308314
Dsymbol s = mod.search_correct(names[i]);
309315
if (s)
316+
{
310317
mod.error(loc, "import '%s' not found, did you mean %s '%s'?", names[i].toChars(), s.kind(), s.toChars());
318+
}
311319
else
312320
mod.error(loc, "import '%s' not found", names[i].toChars());
313321
ad.type = Type.terror;

src/ddmd/expression.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6584,7 +6584,7 @@ extern (C++) final class VarExp : SymbolExp
65846584
* problems when instantiating imported templates passing private
65856585
* variables as alias template parameters.
65866586
*/
6587-
//checkAccess(loc, sc, NULL, var);
6587+
//checkAccess(loc, sc, null, var);
65886588

65896589
if (auto vd = var.isVarDeclaration())
65906590
{

test/fail_compilation/fail15896.d

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
TEST_OUTPUT:
3+
---
4+
fail_compilation/fail15896.d(8): Error: module imports.imp15896 member 'thebar' is private
5+
---
6+
*/
7+
8+
import imports.imp15896 : thebar;
9+
10+
int func()
11+
{
12+
thebar +=1;
13+
return 0;
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module imports.imp15896;
2+
3+
private int thebar=4;

0 commit comments

Comments
 (0)