Skip to content

Commit

Permalink
Merge pull request #3707 from 9rnsr/fix13011
Browse files Browse the repository at this point in the history
Issue 13011 - inout delegate parameter cannot receive exactly same type argument
  • Loading branch information
WalterBright authored and 9rnsr committed Jul 7, 2014
1 parent 6382ff6 commit 4f26498
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/declaration.c
Expand Up @@ -1343,8 +1343,7 @@ void VarDeclaration::semantic(Scope *sc)
error("only parameters or foreach declarations can be ref");
}

if (type->hasWild() &&
!(type->ty == Tpointer && type->nextOf()->ty == Tfunction || type->ty == Tdelegate))
if (type->hasWild())
{
if (storage_class & (STCstatic | STCextern | STCtls | STCgshared | STCmanifest | STCfield) ||
isDataseg()
Expand Down
10 changes: 6 additions & 4 deletions src/mtype.c
Expand Up @@ -2582,6 +2582,10 @@ void TypeNext::checkDeprecated(Loc loc, Scope *sc)

int TypeNext::hasWild()
{
if (ty == Tfunction)
return 0;
if (ty == Tdelegate)
return Type::hasWild();
return mod & MODwild || (next && next->hasWild());
}

Expand Down Expand Up @@ -5539,8 +5543,7 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
error(loc, "functions cannot return scope %s", tf->next->toChars());
errors = true;
}
if (tf->next->hasWild() &&
!(tf->next->ty == Tpointer && tf->next->nextOf()->ty == Tfunction || tf->next->ty == Tdelegate))
if (tf->next->hasWild())
wildreturn = true;
}

Expand Down Expand Up @@ -5623,8 +5626,7 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
}
}

if (t->hasWild() &&
!(t->ty == Tpointer && t->nextOf()->ty == Tfunction || t->ty == Tdelegate))
if (t->hasWild())
{
wildparams |= 1;
//if (tf->next && !wildreturn)
Expand Down
48 changes: 39 additions & 9 deletions test/runnable/testconst.d
Expand Up @@ -2062,19 +2062,34 @@ void test1961c()

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

inout(int) function(inout(int)) notinoutfun1() { return null; }
inout(int) delegate(inout(int)) notinoutfun2() { return null; }
void notinoutfun1(inout(int) function(inout(int)) fn) {}
void notinoutfun2(inout(int) delegate(inout(int)) dg) {}
inout(int) function(inout(int)) notinoutfun1() { return null; }
inout(int) function(inout(int))[] notinoutfun2() { return null; }
inout(int) delegate(inout(int)) notinoutfun3() { return null; }
inout(int) delegate(inout(int))[] notinoutfun4() { return null; }
void notinoutfun1(inout(int) function(inout(int)) fn) {}
void notinoutfun2(inout(int) function(inout(int))[] fn) {}
void notinoutfun3(inout(int) delegate(inout(int)) dg) {}
void notinoutfun4(inout(int) delegate(inout(int))[] dg) {}

void test88()
{
inout(int) function(inout(int)) fp;
inout(int) delegate(inout(int)) dg;
inout(int) function(inout int) fp;
inout(int) delegate(inout int) dg;

static assert(!__traits(compiles, {
inout(int)* p;
}));
inout(int) function(inout int)* fp2p;
inout(int) function(inout int)[] fp2a;
inout(int) function(inout int)[3] fp2s;

inout(int) delegate(inout int)* dg3p;
inout(int) delegate(inout int)[] dg3a;
inout(int) delegate(inout int)[3] dg3s;

int delegate() inout* dg4p;
int delegate() inout[] dg4a;
int delegate() inout[3] dg4s;

static assert(!__traits(compiles, { inout(int)* p; }));
static assert(!__traits(compiles, { inout(int delegate()) dg; }));
}

/************************************/
Expand Down Expand Up @@ -3708,6 +3723,20 @@ void test12403()
func(m);
}

/************************************/
// 13011

void test13011()
{
static size_t hashOf(int delegate() inout val)
{
return 0;
}

int delegate() inout dg;
auto h = hashOf(dg);
}

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

int main()
Expand Down Expand Up @@ -3838,6 +3867,7 @@ int main()
test9209();
test11226();
test11768();
test13011();

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

0 comments on commit 4f26498

Please sign in to comment.