Skip to content

Commit

Permalink
Merge pull request dlang#1464 from 9rnsr/fix9293
Browse files Browse the repository at this point in the history
Issue 9293 - enum struct with StructInitializer reports weird error
  • Loading branch information
WalterBright committed Jan 13, 2013
2 parents 7686d93 + 895f191 commit 7f9d6c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/declaration.c
Expand Up @@ -2013,6 +2013,10 @@ Expression *VarDeclaration::getConstInitializer()
ExpInitializer *ei = getExpInitializer();
if (ei)
return ei->exp;
else if (init)
{
return init->toExpression();
}
}

return NULL;
Expand Down
26 changes: 26 additions & 0 deletions test/runnable/structlit.d
Expand Up @@ -589,6 +589,31 @@ void test9116()
assert(y.x.v == 1); // fails
}

/********************************************/
// 9293

void test9293()
{
static struct A
{
// enum A zero = A(); // This works as expected
enum A zero = {}; // Note the difference here

int opCmp(const ref A a) const
{
assert(0);
}

int opCmp(const A a) const
{
return 0;
}
}

A a;
auto b = a >= A.zero; // Error: A() is not an lvalue
}

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

int main()
Expand All @@ -614,6 +639,7 @@ int main()
test7929();
test7021();
test9116();
test9293();

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

0 comments on commit 7f9d6c8

Please sign in to comment.