Skip to content

Commit

Permalink
Fix Issue 18219 - Private import inside struct leaks symbols when use…
Browse files Browse the repository at this point in the history
…d as VarDeclaration types
  • Loading branch information
RazvanN7 committed Jan 22, 2018
1 parent 66ad69b commit 9bcb80a
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/dmd/dsymbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ extern (C++) class Dsymbol : RootObject
* Returns:
* symbol found, NULL if not
*/
final Dsymbol searchX(Loc loc, Scope* sc, RootObject id)
final Dsymbol searchX(Loc loc, Scope* sc, RootObject id, int flags)
{
//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident.toChars());
Dsymbol s = toAlias();
Expand All @@ -685,7 +685,7 @@ extern (C++) class Dsymbol : RootObject
switch (id.dyncast())
{
case DYNCAST.identifier:
sm = s.search(loc, cast(Identifier)id);
sm = s.search(loc, cast(Identifier)id, flags);
break;
case DYNCAST.dsymbol:
{
Expand Down
8 changes: 5 additions & 3 deletions src/dmd/mtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -2558,7 +2558,7 @@ extern (C++) abstract class Type : RootObject
if (this != Type.terror)
{
if (s)
error(loc, "no property `%s` for type `%s`, did you mean `%s`?", ident.toChars(), toChars(), s.toChars());
error(loc, "no property '%s' for type '%s', did you mean '%s'?", ident.toChars(), toChars(), s.toPrettyChars());
else
error(loc, "no property `%s` for type `%s`", ident.toChars(), toChars());
}
Expand Down Expand Up @@ -6545,7 +6545,9 @@ extern (C++) abstract class TypeQualified : Type

Type t = s.getType(); // type symbol, type alias, or type tuple?
uint errorsave = global.errors;
Dsymbol sm = s.searchX(loc, sc, id);
int flags = t is null ? SearchLocalsOnly : IgnorePrivateImports;

Dsymbol sm = s.searchX(loc, sc, id, flags);
if (sm && !(sc.flags & SCOPE.ignoresymbolvisibility) && !symbolIsVisible(sc, sm))
{
.deprecation(loc, "`%s` is not visible from module `%s`", sm.toPrettyChars(), sc._module.toChars());
Expand Down Expand Up @@ -6591,7 +6593,7 @@ extern (C++) abstract class TypeQualified : Type
sm = t.toDsymbol(sc);
if (sm && id.dyncast() == DYNCAST.identifier)
{
sm = sm.search(loc, cast(Identifier)id);
sm = sm.search(loc, cast(Identifier)id, IgnorePrivateImports);
if (sm)
goto L2;
}
Expand Down
4 changes: 2 additions & 2 deletions src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ private extern (C++) final class TypeSemanticVisitor : Visitor

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

override void visit(TypeClass mtype)
{
//printf("TypeClass::semantic(%s)\n", sym.toChars());
//printf("TypeClass::semantic(%s)\n", mtype.toChars());
if (mtype.deco)
{
if (sc && sc.cppmangle != CPPMANGLE.def)
Expand Down
19 changes: 19 additions & 0 deletions test/fail_compilation/fail18219.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// EXTRA_SOURCES: imports/b18219.d
/*
TEST_OUTPUT:
---
fail_compilation/fail18219.d(15): Error: no property 'Foobar' for type 'AST', did you mean 'b18219.Foobar'?
fail_compilation/fail18219.d(16): Error: no property 'Bar' for type 'AST'
fail_compilation/fail18219.d(17): Error: no property 'fun' for type 'AST', did you mean 'b18219.fun'?
fail_compilation/fail18219.d(18): Error: no property 'Foobar' for type 'AST', did you mean 'b18219.Foobar'?
---
*/
import imports.a18219;

void main()
{
AST.Foobar t;
AST.Bar l;
AST.fun();
AST.Foobar.smeth();
}
2 changes: 1 addition & 1 deletion test/fail_compilation/fail347.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
TEST_OUTPUT:
---
fail_compilation/fail347.d(21): Error: undefined identifier `bbr`, did you mean variable `bar`?
fail_compilation/fail347.d(22): Error: no property `ofo` for type `S`, did you mean `foo`?
fail_compilation/fail347.d(22): Error: no property 'ofo' for type 'S', did you mean 'fail347.S.foo'?
fail_compilation/fail347.d(23): Error: undefined identifier `strlenx`, did you mean function `strlen`?
---
*/
Expand Down
6 changes: 6 additions & 0 deletions test/fail_compilation/imports/a18219.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module a18219;

struct AST
{
import b18219;
}
15 changes: 15 additions & 0 deletions test/fail_compilation/imports/b18219.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module b18219;

class Foobar
{
int a;
this(int a)
{
this.a = a;
}
static int smeth()
{
return 1;
}
}
void fun() {}

0 comments on commit 9bcb80a

Please sign in to comment.