From b16f80834e4f9fa9bd62320f132f77fb22fc65b6 Mon Sep 17 00:00:00 2001 From: k-hara Date: Tue, 29 Jul 2014 15:00:41 +0900 Subject: [PATCH] fix Issue 13221 - [ICE] '0' on line 318 in file 'interpret.c' --- src/interpret.c | 5 ++++- src/mtype.c | 5 +++++ test/fail_compilation/ice13221.d | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/fail_compilation/ice13221.d diff --git a/src/interpret.c b/src/interpret.c index 53949bb66d58..1646371a673c 100644 --- a/src/interpret.c +++ b/src/interpret.c @@ -713,8 +713,11 @@ void ctfeCompile(FuncDeclaration *fd) */ Expression *ctfeInterpret(Expression *e) { - if (e->type == Type::terror) + if (e->op == TOKerror) return e; + //assert(e->type->ty != Terror); // FIXME + if (e->type->ty == Terror) + return new ErrorExp(); unsigned olderrors = global.errors; diff --git a/src/mtype.c b/src/mtype.c index 711127a08fec..e5c365057061 100644 --- a/src/mtype.c +++ b/src/mtype.c @@ -4105,12 +4105,17 @@ Type *TypeSArray::semantic(Loc loc, Scope *sc) dim = dim->optimize(WANTvalue); dim = dim->ctfeInterpret(); + if (dim->op == TOKerror) + goto Lerror; errors = global.errors; dinteger_t d1 = dim->toInteger(); if (errors != global.errors) goto Lerror; + dim = dim->implicitCastTo(sc, tsize_t); dim = dim->optimize(WANTvalue); + if (dim->op == TOKerror) + goto Lerror; errors = global.errors; dinteger_t d2 = dim->toInteger(); if (errors != global.errors) diff --git a/test/fail_compilation/ice13221.d b/test/fail_compilation/ice13221.d new file mode 100644 index 000000000000..b00169e4098f --- /dev/null +++ b/test/fail_compilation/ice13221.d @@ -0,0 +1,23 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/ice13221.d(20): Error: variable r cannot be read at compile time +--- +*/ + +struct Tuple(T...) +{ + T field; + alias field this; +} + +template test(T) {} + +void main() +{ + foreach (r; 0 .. 0) + { + enum i = r; + test!(Tuple!bool[i]); + } +}