Skip to content
Open
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
137 changes: 0 additions & 137 deletions compiler/src/dmd/declaration.d
Original file line number Diff line number Diff line change
Expand Up @@ -449,132 +449,6 @@ extern (C++) final class AliasDeclaration : Declaration
return sa;
}

override bool overloadInsert(Dsymbol s)
{
//printf("[%s] AliasDeclaration::overloadInsert('%s') s = %s %s @ [%s]\n",
// loc.toChars(), toChars(), s.kind(), s.toChars(), s.loc.toChars());

/** Aliases aren't overloadable themselves, but if their Aliasee is
* overloadable they are converted to an overloadable Alias (either
* FuncAliasDeclaration or OverDeclaration).
*
* This is done by moving the Aliasee into such an overloadable alias
* which is then used to replace the existing Aliasee. The original
* Alias (_this_) remains a useless shell.
*
* This is a horrible mess. It was probably done to avoid replacing
* existing AST nodes and references, but it needs a major
* simplification b/c it's too complex to maintain.
*
* A simpler approach might be to merge any colliding symbols into a
* simple Overload class (an array) and then later have that resolve
* all collisions.
*/
if (semanticRun >= PASS.semanticdone)
{
/* Semantic analysis is already finished, and the aliased entity
* is not overloadable.
*/
if (type)
{
/*
If type has been resolved already we could
still be inserting an alias from an import.

If we are handling an alias then pretend
it was inserting and return true, if not then
false since we didn't even pretend to insert something.
*/
return this._import && this.equals(s);
}

// https://issues.dlang.org/show_bug.cgi?id=23865
// only insert if the symbol can be part of a set
const s1 = s.toAlias();
const isInsertCandidate = s1.isFuncDeclaration() || s1.isOverDeclaration() || s1.isTemplateDeclaration();

/* When s is added in member scope by static if, mixin("code") or others,
* aliassym is determined already. See the case in: test/compilable/test61.d
*/
auto sa = aliassym.toAlias();

if (auto td = s.toAlias().isTemplateDeclaration())
s = td.funcroot ? td.funcroot : td;

if (auto fd = sa.isFuncDeclaration())
{
auto fa = new FuncAliasDeclaration(ident, fd);
fa.visibility = visibility;
fa.parent = parent;
aliassym = fa;
if (isInsertCandidate)
return aliassym.overloadInsert(s);
}
if (auto td = sa.isTemplateDeclaration())
{
auto od = new OverDeclaration(ident, td.funcroot ? td.funcroot : td);
od.visibility = visibility;
od.parent = parent;
aliassym = od;
if (isInsertCandidate)
return aliassym.overloadInsert(s);
}
if (auto od = sa.isOverDeclaration())
{
if (sa.ident != ident || sa.parent != parent)
{
od = new OverDeclaration(ident, od);
od.visibility = visibility;
od.parent = parent;
aliassym = od;
}
if (isInsertCandidate)
return od.overloadInsert(s);
}
if (auto os = sa.isOverloadSet())
{
if (sa.ident != ident || sa.parent != parent)
{
os = new OverloadSet(ident, os);
// TODO: visibility is lost here b/c OverloadSets have no visibility attribute
// Might no be a practical issue, b/c the code below fails to resolve the overload anyhow.
// ----
// module os1;
// import a, b;
// private alias merged = foo; // private alias to overload set of a.foo and b.foo
// ----
// module os2;
// import a, b;
// public alias merged = bar; // public alias to overload set of a.bar and b.bar
// ----
// module bug;
// import os1, os2;
// void test() { merged(123); } // should only look at os2.merged
//
// os.visibility = visibility;
os.parent = parent;
aliassym = os;
}
if (isInsertCandidate)
{
os.push(s);
return true;
}
}
return false;
}

/* Don't know yet what the aliased symbol is, so assume it can
* be overloaded and check later for correctness.
*/
if (overnext)
return overnext.overloadInsert(s);
if (s is this)
return true;
overnext = s;
return true;
}

override const(char)* kind() const
{
return "alias";
Expand Down Expand Up @@ -639,17 +513,6 @@ extern (C++) final class OverDeclaration : Declaration
return this.aliassym == s;
}

override bool overloadInsert(Dsymbol s)
{
//printf("OverDeclaration::overloadInsert('%s') aliassym = %p, overnext = %p\n", s.toChars(), aliassym, overnext);
if (overnext)
return overnext.overloadInsert(s);
if (s == this)
return true;
overnext = s;
return true;
}

override bool isOverloadable() const
{
return true;
Expand Down
5 changes: 0 additions & 5 deletions compiler/src/dmd/declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ class AliasDeclaration final : public Declaration

static AliasDeclaration *create(Loc loc, Identifier *id, Type *type);
AliasDeclaration *syntaxCopy(Dsymbol *) override;
bool overloadInsert(Dsymbol *s) override;
const char *kind() const override;
Type *getType() override;
bool isOverloadable() const override;
Expand All @@ -218,7 +217,6 @@ class OverDeclaration final : public Declaration

const char *kind() const override;
bool equals(const RootObject * const o) const override;
bool overloadInsert(Dsymbol *s) override;

Dsymbol *isUnique();
bool isOverloadable() const override;
Expand Down Expand Up @@ -699,7 +697,6 @@ class FuncDeclaration : public Declaration
Expressions *fdensureParams(Expressions *fdep);
bool equals(const RootObject * const o) const override final;

bool overloadInsert(Dsymbol *s) override;
bool inUnittest();
LabelDsymbol *searchLabel(Identifier *ident, Loc loc);
const char *toPrettyChars(bool QualifyTypes = false) override;
Expand Down Expand Up @@ -787,7 +784,6 @@ class PostBlitDeclaration final : public FuncDeclaration
bool isVirtual() const override;
bool addPreInvariant() override;
bool addPostInvariant() override;
bool overloadInsert(Dsymbol *s) override;

void accept(Visitor *v) override { v->visit(this); }
};
Expand All @@ -800,7 +796,6 @@ class DtorDeclaration final : public FuncDeclaration
bool isVirtual() const override;
bool addPreInvariant() override;
bool addPostInvariant() override;
bool overloadInsert(Dsymbol *s) override;

void accept(Visitor *v) override { v->visit(this); }
};
Expand Down
13 changes: 0 additions & 13 deletions compiler/src/dmd/dimport.d
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,6 @@ extern (C++) final class Import : Dsymbol
scopesym.addAccessiblePackage(mod, visibility); // d
}

override bool overloadInsert(Dsymbol s)
{
/* Allow multiple imports with the same package base, but disallow
* alias collisions
* https://issues.dlang.org/show_bug.cgi?id=5412
*/
assert(ident && ident == s.ident);
if (aliasId)
return false;
const imp = s.isImport();
return imp && !imp.aliasId;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dmd/dsymbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -677,12 +677,6 @@ extern (C++) class Dsymbol : ASTNode
return "symbol";
}

bool overloadInsert(Dsymbol s)
{
//printf("Dsymbol::overloadInsert('%s')\n", s.toChars());
return false;
}

/*********************************
* Returns:
* SIZE_INVALID when the size cannot be determined
Expand Down
Loading
Loading