Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix Issue 9293 - enum struct with StructInitializer reports weird error

`VarDeclaration::getConstInitializer` should return an actual expression, even if init is not an `ExpInitializer`.
  • Loading branch information...
commit 895f19174dffc9088c0516f2c8cc47f8f4c589fa 1 parent c7215bc
Hara Kenji 9rnsr authored
Showing with 30 additions and 0 deletions.
  1. +4 −0 src/declaration.c
  2. +26 −0 test/runnable/structlit.d
4 src/declaration.c
View
@@ -2013,6 +2013,10 @@ Expression *VarDeclaration::getConstInitializer()
ExpInitializer *ei = getExpInitializer();
if (ei)
return ei->exp;
+ else if (init)
+ {
+ return init->toExpression();
+ }
}
return NULL;
26 test/runnable/structlit.d
View
@@ -590,6 +590,31 @@ void test9116()
}
/********************************************/
+// 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()
{
@@ -614,6 +639,7 @@ int main()
test7929();
test7021();
test9116();
+ test9293();
printf("Success\n");
return 0;
Please sign in to comment.
Something went wrong with that request. Please try again.