Skip to content

Commit

Permalink
Fixes Issue 7420 - Return ErrorExp on error to avoid duplicate errors.
Browse files Browse the repository at this point in the history
Force 32bit diagnostics for test-case.
  • Loading branch information
AndrejMitrovic committed Nov 1, 2012
1 parent 81860f8 commit 550c25d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/optimize.c
Expand Up @@ -180,6 +180,7 @@ Expression *fromConstInitializer(int result, Expression *e1)
!(v->storage_class & STCtemplateparameter))
{
e1->error("variable %s cannot be read at compile time", v->toChars());
e->type = Type::terror;
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions test/fail_compilation/diag7420.d
@@ -0,0 +1,25 @@
// REQUIRED_ARGS: -m32
/*
TEST_OUTPUT:
---
fail_compilation/diag7420.d(3): Error: variable x cannot be read at compile time
fail_compilation/diag7420.d(3): while evaluating: static assert(x < 4)
fail_compilation/diag7420.d(4): Error: variable y cannot be read at compile time
fail_compilation/diag7420.d(4): while evaluating: static assert(y == "abc")
fail_compilation/diag7420.d(5): Error: variable y cannot be read at compile time
fail_compilation/diag7420.d(5): while evaluating: static assert(cast(ubyte[])y != null)
fail_compilation/diag7420.d(6): Error: variable y cannot be read at compile time
fail_compilation/diag7420.d(6): while evaluating: static assert(cast(int)y[0u] == 1)
fail_compilation/diag7420.d(7): Error: variable y cannot be read at compile time
fail_compilation/diag7420.d(7): while evaluating: static assert(y[0u..1u].length == 1u)
---
*/

#line 1
int x = 2;
char[] y = "abc".dup;
static assert(x < 4);
static assert(y == "abc");
static assert(cast(ubyte[])y != null);
static assert(y[0] == 1);
static assert(y[0..1].length == 1);

0 comments on commit 550c25d

Please sign in to comment.