Bug 4460 – Regression(2.036) ICE(e2ir.c) when compiling foreach over associative array literal

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-07-14T12:11:00Z
Last change time
2012-04-11T01:01:07Z
Keywords
ice-on-valid-code, patch
Assigned to
nobody
Creator
adrian

Comments

Comment #0 by adrian — 2010-07-14T12:11:41Z
import std.stdio; void main() { foreach (s, i; [ "a":1, "b":2 ]) { writeln(s, i); } } The above does not compile. DMD 2.047 gives up with message "Internal error: e2ir.c 4616".
Comment #1 by clugdbug — 2010-09-24T00:19:55Z
This worked in 2.035. The import std.stdio and writeln are not necessary to demonstrate the ICE.
Comment #2 by clugdbug — 2010-09-29T00:24:30Z
The regression was introduced in svn 218, static arrays as values. The relevant change was in statement.c, ForeachStatement::semantic. --- case Taarray: if (!checkForArgTypes()) return this; taa = (TypeAArray *)tab; if (dim < 1 || dim > 2) { error("only one or two arguments for associative array foreach"); break; } -#if 0 +#if 1 /* This currently fails if Key or Value is a static array. * The fix is to make static arrays a value type, not the * kludge they currently are. */ tab = taa->impl->type; goto Lagain;
Comment #3 by clugdbug — 2010-11-22T01:57:10Z
*** Issue 4990 has been marked as a duplicate of this issue. ***
Comment #4 by braddr — 2011-02-06T15:39:52Z
Mass migration of bugs marked as x86-64 to just x86. The platform run on isn't what's relevant, it's if the app is a 32 or 64 bit app.
Comment #5 by andrden — 2011-04-19T07:56:24Z
2.052 the following still doesn't compile: Internal error: e2ir.c 4835 void main(){ auto a = ["k":"v"].keys; }
Comment #6 by ibuclaw — 2011-04-23T12:39:40Z
Patch: diff --git a/src/mtype.c b/src/mtype.c index f8ad06e..1d1fcd6 100644 --- a/src/mtype.c +++ b/src/mtype.c @@ -4173,6 +4173,17 @@ Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident) else #endif { + /* Create a new temporary variable for literal arrays. + */ + if (e->op == TOKassocarrayliteral) + { + Identifier *idtmp = Lexer::uniqueId("__aatmp"); + VarDeclaration *aatmp = new VarDeclaration(loc, e->type, idtmp, new ExpInitializer(0, e)); + aatmp->storage_class |= STCctfe; + Expression *ae = new DeclarationExp(loc, aatmp); + e = new CommaExp(loc, ae, new VarExp(loc, aatmp)); + e = e->semantic(sc); + } e->type = getImpl()->type; e = e->type->dotExp(sc, e, ident); //e = Type::dotExp(sc, e, ident);
Comment #7 by clugdbug — 2011-04-28T08:41:30Z
*** Issue 5590 has been marked as a duplicate of this issue. ***
Comment #8 by ibuclaw — 2011-04-28T13:49:27Z
You know I never actually checked to see if this patch worked in DMD... ... it doesn't work DMD. Now why would that be? Seems to because of a similar reason to issue5683 - backend is simply not getting the passing of the value right.
Comment #9 by yebblies — 2011-07-09T22:04:57Z
https://github.com/D-Programming-Language/dmd/pull/221 This also re-enables the check that the index is not ref, and a couple of others.
Comment #10 by bugzilla — 2011-08-02T12:14:41Z
Comment #11 by clugdbug — 2012-04-11T01:01:07Z
*** Issue 5675 has been marked as a duplicate of this issue. ***