Skip to content

Commit

Permalink
Merge pull request #1200 from AndrejMitrovic/Fix7420
Browse files Browse the repository at this point in the history
Fix Issue 7420 - Duplicate "cannot be read at compile time" error messages
  • Loading branch information
9rnsr committed Nov 10, 2012
2 parents e1a466e + 550c25d commit 8158595
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 8158595

Please sign in to comment.