Skip to content

Commit

Permalink
Fix Issue 17441 - Template instantiation reused when arguments are mo… (
Browse files Browse the repository at this point in the history
dlang#10724)

Fix Issue 17441 - Template instantiation reused when arguments are mo…
merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
  • Loading branch information
BorisCarvajal authored and dlang-bot committed Jan 19, 2020
1 parent 7ee2b23 commit b7c279f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/dmd/dmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import dmd.root.filename;
import dmd.root.outbuffer;
import dmd.root.port;
import dmd.root.rmem;
import dmd.root.rootobject;
import dmd.semantic2;
import dmd.semantic3;
import dmd.utils;
Expand Down Expand Up @@ -231,6 +232,15 @@ extern (C++) class Package : ScopeDsymbol
return "package";
}

override bool equals(const RootObject o) const
{
// custom 'equals' for bug 17441. "package a" and "module a" are not equal
if (this == o)
return true;
auto p = cast(Package)o;
return p && isModule() == p.isModule() && ident.equals(p.ident);
}

/****************************************************
* Input:
* packages[] the pkg1.pkg2 of pkg1.pkg2.mod
Expand Down
2 changes: 2 additions & 0 deletions src/dmd/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Package : public ScopeDsymbol

const char *kind() const;

bool equals(const RootObject *o) const;

Package *isPackage() { return this; }

bool isAncestorPackageOf(const Package * const pkg) const;
Expand Down
1 change: 1 addition & 0 deletions test/compilable/imports/test17441foo/bar.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module imports.test17441foo.bar;
1 change: 1 addition & 0 deletions test/compilable/imports/test17441foo/package.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module imports.test17441foo;
8 changes: 8 additions & 0 deletions test/compilable/test17441.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import m1 = imports.test17441foo.bar;
import m2 = imports.test17441foo;
alias p = __traits(parent, m1);
enum e(alias thing) = thing.stringof;

static assert(e!m1 == m1.stringof);
static assert(e!m2 == m2.stringof);
static assert( e!p == p.stringof );

0 comments on commit b7c279f

Please sign in to comment.