Skip to content

Commit

Permalink
Merge pull request #4003 from 9rnsr/2.066
Browse files Browse the repository at this point in the history
Cherry-picking pull request #3961 for 2.066.1
  • Loading branch information
9rnsr committed Sep 18, 2014
2 parents 0acbd54 + 7507f09 commit 0588458
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/constfold.c
Expand Up @@ -1704,11 +1704,13 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
e->type = type;
}
else if ((e1->op == TOKarrayliteral || e1->op == TOKnull) &&
e1->type->toBasetype()->nextOf() &&
e1->type->toBasetype()->nextOf()->equals(e2->type))
{
ArrayLiteralExp *es1;
if (e1->op == TOKarrayliteral)
{ es1 = (ArrayLiteralExp *)e1;
{
es1 = (ArrayLiteralExp *)e1;
es1 = new ArrayLiteralExp(es1->loc, (Expressions *)es1->elements->copy());
es1->elements->push(e2);
}
Expand Down
12 changes: 11 additions & 1 deletion src/dsymbol.c
Expand Up @@ -455,14 +455,24 @@ Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, RootObject *id)
Dsymbol *s = toAlias();
Dsymbol *sm;

if (Declaration *d = s->isDeclaration())
{
if (d->inuse)
{
::error(loc, "circular reference to '%s'", d->toPrettyChars());
return NULL;
}
}

switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
sm = s->search(loc, (Identifier *)id);
break;

case DYNCAST_DSYMBOL:
{ // It's a template instance
{
// It's a template instance
//printf("\ttemplate instance id\n");
Dsymbol *st = (Dsymbol *)id;
TemplateInstance *ti = st->isTemplateInstance();
Expand Down
12 changes: 0 additions & 12 deletions src/mtype.c
Expand Up @@ -6804,18 +6804,6 @@ void TypeIdentifier::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsy
}

Dsymbol *s = sc->search(loc, ident, &scopesym);
if (s)
{
Declaration *d = s->isDeclaration();
if (d && d->inuse)
{
error(loc, "circular reference to '%s'", d->toPrettyChars());
*pe = NULL;
*ps = NULL;
*pt = Type::terror;
return;
}
}
resolveHelper(loc, sc, s, scopesym, pe, pt, ps, intypeid);
if (*pt)
(*pt) = (*pt)->addMod(mod);
Expand Down
65 changes: 65 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -7000,6 +7000,69 @@ void test13154()
assert(floats2 == [2, 1, 0]);
}

/***************************************************/
// 13472

class A13472
{
int a;
}

void test13472()
{
A13472[] test;
test.length = 4;
auto b = test[0..2] ~ null ~ test[2..$];
assert(b.length == 5);
}

/***************************************************/
// 13476

template ParameterTypeTuple13476(func...)
{
static if (is(typeof(*func[0]) P == function))
alias ParameterTypeTuple13476 = P;
else
static assert(0, "argument has no parameters");
}

int flag13476;

__gshared extern(C) void function(int) nothrow someFunc13476 = &Stub13476!someFunc13476;

extern(C) auto Stub13476(alias func)(ParameterTypeTuple13476!func args)
{
++flag13476;
extern(C) void function(int) nothrow impl = (i) { };
return (func = impl)(args);
}

__gshared extern(C) void function(int) nothrow someFunc13476Alt = &Stub13476Alt!someFunc13476AltP;
__gshared extern(C) void function(int) nothrow* someFunc13476AltP = &someFunc13476Alt;

extern(C) auto Stub13476Alt(alias func)(int args) nothrow
{
++flag13476;
extern(C) void function(int) nothrow impl = (i) {};
return (*func = impl)(args);
}

void test13476()
{
assert(flag13476 == 0);

someFunc13476(42);
assert(flag13476 == 1);
someFunc13476(43);
assert(flag13476 == 1);

someFunc13476Alt(42);
assert(flag13476 == 2);
someFunc13476Alt(43);
assert(flag13476 == 2);
}

/***************************************************/

int main()
Expand Down Expand Up @@ -7291,6 +7354,8 @@ int main()
test12153();
test12937();
test13154();
test13472();
test13476();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 0588458

Please sign in to comment.