Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 11259: __traits(isSame) fails on the result of __traits(parent) if parent is a package #7095

Merged
merged 1 commit into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/ddmd/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,17 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
if (auto fa2 = s2.isFuncAliasDeclaration())
s2 = fa2.toAliasFunc();

// https://issues.dlang.org/show_bug.cgi?id=11259
// compare import symbol to a package symbol
static bool cmp(Dsymbol s1, Dsymbol s2)
{
auto imp = s1.isImport();
return imp && imp.pkg && imp.pkg == s2.isPackage();
}

if (cmp(s1,s2) || cmp(s2,s1))
return True();

return (s1 == s2) ? True() : False();
}
if (e.ident == Id.getUnitTests)
Expand Down
25 changes: 25 additions & 0 deletions test/compilable/test11259.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// https://issues.dlang.org/show_bug.cgi?id=11259

version (Posix)
{
// smallest druntime module without imports on posix
import core.sys.posix.libgen;
static assert(__traits(isSame, __traits(parent, core.sys.posix.libgen), core.sys.posix));
static assert(__traits(isSame, core.sys.posix, __traits(parent, core.sys.posix.libgen)));

static assert(__traits(isSame, __traits(parent, core.sys.posix), core.sys));
static assert(__traits(isSame, core.sys, __traits(parent, core.sys.posix)));
}
else
{
// smallest module without imports for windows
import core.sys.windows.lmuseflg;
static assert(__traits(isSame, __traits(parent, core.sys.windows.lmuseflg), core.sys.windows));
static assert(__traits(isSame, core.sys.windows, __traits(parent, core.sys.windows.lmuseflg)));

static assert(__traits(isSame, __traits(parent, core.sys.windows), core.sys));
static assert(__traits(isSame, core.sys, __traits(parent, core.sys.windows)));
}

static assert(__traits(isSame, __traits(parent, core.sys), core));
static assert(__traits(isSame, core, __traits(parent, core.sys)));