Skip to content

Commit

Permalink
fix Issue 13275 - Wrong di header generation on if and foreach statem…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
9rnsr committed Aug 15, 2014
1 parent 9539a19 commit 03f1399
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/hdrgen.c
Expand Up @@ -263,8 +263,7 @@ class PrettyPrintVisitor : public Visitor
Parameter *a = (*s->arguments)[i];
if (i)
buf->writestring(", ");
if (a->storageClass & STCref)
buf->writestring((char*)"ref ");
StorageClassDeclaration::stcToCBuffer(buf, a->storageClass);
if (a->type)
typeToBuffer(a->type, a->ident);
else
Expand Down Expand Up @@ -313,15 +312,16 @@ class PrettyPrintVisitor : public Visitor
void visit(IfStatement *s)
{
buf->writestring("if (");
if (s->arg)
if (Parameter *a = s->arg)
{
if (s->arg->type)
typeToBuffer(s->arg->type, s->arg->ident);
StorageClass stc = a->storageClass;
if (!a->type && !stc)
stc = STCauto;
StorageClassDeclaration::stcToCBuffer(buf, stc);
if (a->type)
typeToBuffer(a->type, a->ident);
else
{
buf->writestring("auto ");
buf->writestring(s->arg->ident->toChars());
}
buf->writestring(a->ident->toChars());
buf->writestring(" = ");
}
s->condition->accept(this);
Expand Down
40 changes: 40 additions & 0 deletions test/compilable/extra-files/header2.d
Expand Up @@ -85,3 +85,43 @@ void foo11217()( auto ref int[] arr) {}
void foo11217()( scope int[] arr) {}
void foo11217()( in int[] arr) {}
void foo11217()( inout int[] arr) {}

// 13275
void test13275()
{
if ( auto n = 1) {}
if ( const n = 1) {}
if ( immutable n = 1) {}
if (shared n = 1) {}
if (shared const n = 1) {}

if ( int n = 1) {}

if ( const int n = 1) {}
if ( immutable int n = 1) {}
if (shared int n = 1) {}
if (shared const int n = 1) {}

if ( const(int) n = 1) {}
if ( immutable(int) n = 1) {}
if (shared (int) n = 1) {}
if (shared const(int) n = 1) {}

foreach ( e; [1,2]) {}
foreach ( const e; [1,2]) {}
foreach ( immutable e; [1,2]) {}
foreach (shared e; [1,2]) {}
foreach (shared const e; [1,2]) {}

foreach ( int e; [1,2]) {}
foreach ( const int e; [1,2]) {}
foreach ( immutable int e; [1,2]) {}
foreach (shared int e; [1,2]) {}
foreach (shared const int e; [1,2]) {}

foreach ( int e; [1,2]) {}
foreach ( const(int) e; [1,2]) {}
foreach ( immutable(int) e; [1,2]) {}
foreach (shared (int) e; [1,2]) {}
foreach (shared const(int) e; [1,2]) {}
}
1 change: 1 addition & 0 deletions test/compilable/extra-files/header2.di
Expand Up @@ -87,3 +87,4 @@ void foo11217()(in int[] arr)
void foo11217()(inout int[] arr)
{
}
void test13275();
91 changes: 91 additions & 0 deletions test/compilable/extra-files/header2i.di
Expand Up @@ -105,3 +105,94 @@ void foo11217()(in int[] arr)
void foo11217()(inout int[] arr)
{
}
void test13275()
{
if (auto n = 1)
{
}
if (const n = 1)
{
}
if (immutable n = 1)
{
}
if (shared n = 1)
{
}
if (const shared n = 1)
{
}
if (int n = 1)
{
}
if (const int n = 1)
{
}
if (immutable int n = 1)
{
}
if (shared int n = 1)
{
}
if (const shared int n = 1)
{
}
if (const(int) n = 1)
{
}
if (immutable(int) n = 1)
{
}
if (shared(int) n = 1)
{
}
if (shared const(int) n = 1)
{
}
foreach (e; [1, 2])
{
}
foreach (const e; [1, 2])
{
}
foreach (immutable e; [1, 2])
{
}
foreach (shared e; [1, 2])
{
}
foreach (const shared e; [1, 2])
{
}
foreach (int e; [1, 2])
{
}
foreach (const int e; [1, 2])
{
}
foreach (immutable int e; [1, 2])
{
}
foreach (shared int e; [1, 2])
{
}
foreach (const shared int e; [1, 2])
{
}
foreach (int e; [1, 2])
{
}
foreach (const(int) e; [1, 2])
{
}
foreach (immutable(int) e; [1, 2])
{
}
foreach (shared(int) e; [1, 2])
{
}
foreach (shared const(int) e; [1, 2])
{
}
}

0 comments on commit 03f1399

Please sign in to comment.