Skip to content

Commit ce24a5b

Browse files
committed
Fix Issue 18219 - Private import inside struct leaks symbols when used as VarDeclaration types
1 parent 8d6efa5 commit ce24a5b

7 files changed

Lines changed: 50 additions & 8 deletions

File tree

src/dmd/dsymbol.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ extern (C++) class Dsymbol : RootObject
687687
* Returns:
688688
* symbol found, NULL if not
689689
*/
690-
final Dsymbol searchX(Loc loc, Scope* sc, RootObject id)
690+
final Dsymbol searchX(Loc loc, Scope* sc, RootObject id, int flags)
691691
{
692692
//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars());
693693
Dsymbol s = toAlias();
@@ -703,7 +703,7 @@ extern (C++) class Dsymbol : RootObject
703703
switch (id.dyncast())
704704
{
705705
case DYNCAST.identifier:
706-
sm = s.search(loc, cast(Identifier)id);
706+
sm = s.search(loc, cast(Identifier)id, flags);
707707
break;
708708
case DYNCAST.dsymbol:
709709
{

src/dmd/mtype.d

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2562,7 +2562,7 @@ extern (C++) abstract class Type : RootObject
25622562
if (this != Type.terror)
25632563
{
25642564
if (s)
2565-
error(loc, "no property '%s' for type '%s', did you mean '%s'?", ident.toChars(), toChars(), s.toChars());
2565+
error(loc, "no property '%s' for type '%s', did you mean '%s'?", ident.toChars(), toChars(), s.toPrettyChars());
25662566
else
25672567
error(loc, "no property '%s' for type '%s'", ident.toChars(), toChars());
25682568
}
@@ -6566,7 +6566,9 @@ extern (C++) abstract class TypeQualified : Type
65666566

65676567
Type t = s.getType(); // type symbol, type alias, or type tuple?
65686568
uint errorsave = global.errors;
6569-
Dsymbol sm = s.searchX(loc, sc, id);
6569+
int flags = t is null ? SearchLocalsOnly : IgnorePrivateImports;
6570+
6571+
Dsymbol sm = s.searchX(loc, sc, id, flags);
65706572
if (sm && !(sc.flags & SCOPE.ignoresymbolvisibility) && !symbolIsVisible(sc, sm))
65716573
{
65726574
.deprecation(loc, "%s is not visible from module %s", sm.toPrettyChars(), sc._module.toChars());
@@ -6612,7 +6614,7 @@ extern (C++) abstract class TypeQualified : Type
66126614
sm = t.toDsymbol(sc);
66136615
if (sm && id.dyncast() == DYNCAST.identifier)
66146616
{
6615-
sm = sm.search(loc, cast(Identifier)id);
6617+
sm = sm.search(loc, cast(Identifier)id, IgnorePrivateImports);
66166618
if (sm)
66176619
goto L2;
66186620
}

src/dmd/typesem.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ private extern (C++) final class TypeSemanticVisitor : Visitor
12361236

12371237
override void visit(TypeStruct mtype)
12381238
{
1239-
//printf("TypeStruct::semantic('%s')\n", sym.toChars());
1239+
//printf("TypeStruct::semantic('%s')\n", mtype.toChars());
12401240
if (mtype.deco)
12411241
{
12421242
if (sc && sc.cppmangle != CPPMANGLE.def)
@@ -1279,7 +1279,7 @@ private extern (C++) final class TypeSemanticVisitor : Visitor
12791279

12801280
override void visit(TypeClass mtype)
12811281
{
1282-
//printf("TypeClass::semantic(%s)\n", sym.toChars());
1282+
//printf("TypeClass::semantic(%s)\n", mtype.toChars());
12831283
if (mtype.deco)
12841284
{
12851285
if (sc && sc.cppmangle != CPPMANGLE.def)

test/fail_compilation/fail18219.d

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// EXTRA_SOURCES: imports/b18219.d
2+
/*
3+
TEST_OUTPUT:
4+
---
5+
fail_compilation/fail18219.d(15): Error: no property 'Foobar' for type 'AST', did you mean 'b18219.Foobar'?
6+
fail_compilation/fail18219.d(16): Error: no property 'Bar' for type 'AST'
7+
fail_compilation/fail18219.d(17): Error: no property 'fun' for type 'AST', did you mean 'b18219.fun'?
8+
fail_compilation/fail18219.d(18): Error: no property 'Foobar' for type 'AST', did you mean 'b18219.Foobar'?
9+
---
10+
*/
11+
import imports.a18219;
12+
13+
void main()
14+
{
15+
AST.Foobar t;
16+
AST.Bar l;
17+
AST.fun();
18+
AST.Foobar.smeth();
19+
}

test/fail_compilation/fail347.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
TEST_OUTPUT:
33
---
44
fail_compilation/fail347.d(21): Error: undefined identifier `bbr`, did you mean variable `bar`?
5-
fail_compilation/fail347.d(22): Error: no property 'ofo' for type 'S', did you mean 'foo'?
5+
fail_compilation/fail347.d(22): Error: no property 'ofo' for type 'S', did you mean 'fail347.S.foo'?
66
fail_compilation/fail347.d(23): Error: undefined identifier `strlenx`, did you mean function `strlen`?
77
---
88
*/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module a18219;
2+
3+
struct AST
4+
{
5+
import b18219;
6+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module b18219;
2+
3+
class Foobar
4+
{
5+
int a;
6+
this(int a)
7+
{
8+
this.a = a;
9+
}
10+
static int smeth()
11+
{
12+
return 1;
13+
}
14+
}
15+
void fun() {}

0 commit comments

Comments
 (0)