Skip to content
Closed
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
17 changes: 9 additions & 8 deletions src/aliasthis.d
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,18 @@ extern (C++) Expression resolveAliasThis(Scope* sc, Expression e, bool gag = fal
{
if (e.op == TOKvar)
{
if (auto fd = (cast(VarExp)e).var.isFuncDeclaration())
auto ve = cast(VarExp)e;
if (auto fd = ve.var.isFuncDeclaration())
{
// Bugzilla 13009: Support better match for the overloaded alias this.
bool hasOverloads;
if (auto f = fd.overloadModMatch(loc, tthis, hasOverloads))
auto f = fd.overloadModMatch(loc, tthis, ve.hasOverloads);
if (!f && !ve.hasOverloads) // no match
e = new ErrorExp();
else
{
if (!hasOverloads)
fd = f; // use exact match
e = new VarExp(loc, fd, hasOverloads);
e.type = f.type;
e = new CallExp(loc, e);
ve.var = !ve.hasOverloads ? f : fd;
ve.type = f ? f.type : Type.tambig;
e = new CallExp(loc, ve);
goto L1;
}
}
Expand Down
36 changes: 32 additions & 4 deletions src/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,34 @@ extern (C++) Expression implicitCastTo(Expression e, Scope* sc, Type t)
semanticTypeInfo(sc, (cast(TypeDArray)tb).next);
}

override void visit(SymOffExp e)
{
visit(cast(Expression)e);
if (!e.hasOverloads)
return;

if (result.op == TOKsymoff)
{
auto se = cast(SymOffExp)result;
if (!se.hasOverloads)
se.checkDeprecated(sc, se.var);
}
}

override void visit(DelegateExp e)
{
visit(cast(Expression)e);
if (!e.hasOverloads)
return;

if (result.op == TOKdelegate)
{
auto de = cast(DelegateExp)result;
if (!de.hasOverloads)
de.checkDeprecated(sc, de.func);
}
}

override void visit(SliceExp e)
{
visit(cast(Expression)e);
Expand Down Expand Up @@ -2116,12 +2144,12 @@ extern (C++) Expression castTo(Expression e, Scope* sc, Type t)
}

// Look for pointers to functions where the functions are overloaded.
if (e.hasOverloads &&
typeb.ty == Tpointer && typeb.nextOf().ty == Tfunction &&
if (typeb.ty == Tpointer && typeb.nextOf().ty == Tfunction &&
(tb.ty == Tpointer || tb.ty == Tdelegate) && tb.nextOf().ty == Tfunction)
{
FuncDeclaration f = e.var.isFuncDeclaration();
f = f ? f.overloadExactMatch(tb.nextOf()) : null;
auto f = e.var.isFuncDeclaration();
if (f && e.hasOverloads)
f = f.overloadExactMatch(tb.nextOf());
if (f)
{
if (tb.ty == Tdelegate)
Expand Down
14 changes: 14 additions & 0 deletions src/declaration.d
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,13 @@ public:
error("cannot alias an expression %s", e.toChars());
t = Type.terror;
}
else if (e.op == TOKvar)
{
auto ve = cast(VarExp)e;
auto f = s.isFuncDeclaration();
if (!ve.hasOverloads && f && !f.isFuncAliasDeclaration())
s = new FuncAliasDeclaration(ident, f, false);
}
}
type = t;
}
Expand Down Expand Up @@ -1076,6 +1083,13 @@ public:
type = _init.toExpression().type;
if (needctfe)
sc = sc.endCTFE();

if (type.isAmbiguous())
{
type = Type.terror;
return;
}

inuse--;
inferred = 1;
/* This is a kludge to support the existing syntax for RAII
Expand Down
1 change: 1 addition & 0 deletions src/declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ class FuncDeclaration : public Declaration
void semantic2(Scope *sc);
void semantic3(Scope *sc);
bool functionSemantic();
bool functionSemantic(Loc loc);
bool functionSemantic3();
// called from semantic3
VarDeclaration *declareThis(Scope *sc, AggregateDeclaration *ad);
Expand Down
15 changes: 12 additions & 3 deletions src/dmangle.d
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ public:

override void visit(TypeFunction t)
{
if (t.isAmbiguous())
{
buf.writestring("_ambiguous_");
return;
}

//printf("TypeFunction.toDecoBuffer() t = %p %s\n", t, t.toChars());
//static int nest; if (++nest == 50) *(char*)0=0;
mangleFuncType(t, t, t.mod, t.next);
Expand Down Expand Up @@ -829,14 +835,17 @@ extern (C++) const(char)* mangle(Dsymbol s)
*/
extern (C++) const(char)* mangleExact(FuncDeclaration fd)
{
if (!fd.mangleString)
const(char)* s = fd.mangleString;
if (!s)
{
OutBuffer buf;
scope Mangler v = new Mangler(&buf);
v.mangleExact(fd);
fd.mangleString = buf.extractString();
s = buf.extractString();
if (!fd.flags)
fd.mangleString = s;
}
return fd.mangleString;
return s;
}

extern (C++) void mangleToBuffer(Type t, OutBuffer* buf)
Expand Down
8 changes: 8 additions & 0 deletions src/e2ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -3423,6 +3423,14 @@ elem *toElem(Expression *e, IRState *irs)
int directcall = 0;
//printf("DelegateExp::toElem() '%s'\n", de->toChars());

if (de->hasOverloads)
{
assert(de->type->ty == Tdelegate);
de->func = de->func->overloadExactMatch(de->type->nextOf());
}
else
de->func = de->func->toAliasFunc();

if (de->func->semanticRun == PASSsemantic3done)
{
// Bug 7745 - only include the function if it belongs to this module
Expand Down
Loading