Skip to content

Commit

Permalink
fix Issue 8595 - typeof(return) inside opApply loop always int
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Aug 28, 2012
1 parent a5c56ac commit 5a8204f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/mtype.c
Expand Up @@ -40,6 +40,7 @@
#include "scope.h"
#include "init.h"
#include "expression.h"
#include "statement.h"
#include "attrib.h"
#include "declaration.h"
#include "template.h"
Expand Down Expand Up @@ -7075,11 +7076,15 @@ Dsymbol *TypeReturn::toDsymbol(Scope *sc)
Type *TypeReturn::semantic(Loc loc, Scope *sc)
{
Type *t;
if (!sc->func)
FuncDeclaration *func = sc->func;
if (!func)
{ error(loc, "typeof(return) must be inside function");
goto Lerr;
}
t = sc->func->type->nextOf();
if (func->fes)
func = func->fes->func;

t = func->type->nextOf();
if (!t)
{
error(loc, "cannot use typeof(return) inside function %s with inferred return type", sc->func->toChars());
Expand Down
20 changes: 20 additions & 0 deletions test/runnable/foreach5.d
Expand Up @@ -387,6 +387,26 @@ void test7814()
}
}

/***************************************/
// 8595

struct OpApply8595
{
int opApply(int delegate(ref int) dg)
{
assert(0);
}
}

string test8595()
{
foreach (elem; OpApply8595.init)
{
static assert(is(typeof(return) == string));
}
assert(0);
}

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

int main()
Expand Down

0 comments on commit 5a8204f

Please sign in to comment.