digitalmars.D.bugs - [Issue 4826] New: "cannot create associative array" and compiler crash
- d-bugmail puremagic.com (57/57) Sep 05 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4826
- d-bugmail puremagic.com (27/27) Sep 05 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4826
- d-bugmail puremagic.com (11/11) Sep 05 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4826
- d-bugmail puremagic.com (21/21) Sep 06 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4826
- d-bugmail puremagic.com (14/14) Sep 07 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4826
- d-bugmail puremagic.com (14/14) Sep 07 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4826
- d-bugmail puremagic.com (63/63) Sep 08 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4826
- d-bugmail puremagic.com (12/12) Sep 11 2010 http://d.puremagic.com/issues/show_bug.cgi?id=4826
http://d.puremagic.com/issues/show_bug.cgi?id=4826 Summary: "cannot create associative array" and compiler crash Product: D Version: D2 Platform: x86_64 OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: brian-schott cox.net Created an attachment (id=746) Code that fails DMD fails to compile the attached code, printing "Error: cannot create associative array T[string]" before crashing. Error message printed by GDB: Program received signal SIGSEGV, Segmentation fault. 0x0817f8b7 in TemplateInstance::semantic (this=0x953b418, sc=0x0, fargs=0x0) at template.c:3554 3554 tinst = sc->tinst; Backtrace: fargs=0x0) at template.c:3554 at template.c:3524 at mtype.c:6942 tparam=0x82121e0, parameters=0x82120d0, dedtypes=0xffffc458) at template.c:1881 tparam=0x82121e0, parameters=0x82120d0, dedtypes=0xffffc458) at template.c:2412 this=0x8212e80, sc=0x9206218, loc=..., targsi=0x0, ethis=0x94dd5b0, fargs=0x94dd600, dedargs=0xffffc600) at template.c:1109 sc=0x9206218, loc=..., targsi=0x0, ethis=0x94dd5b0, fargs=0x94dd600, flags=0) at template.c:1470 at expression.c:6929 at expression.c:8876 at statement.c:245 at statement.c:464 at func.c:1213 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 05 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4826 Here's the code that fails: The second opIndexAssign is written this way because of bug 2972. module testcase; struct SomeStruct { void opIndexAssign(T)(T[string] value, string key) if(is(T : string) || is(T : int)) { } void opIndexAssign(T)(SomeStruct value, string key) if(is(T : SomeStruct)) { } } void main(string[] args) { auto t = SomeStruct(); t["test"] = ["key": "value", "otherKey": "otherValue"]; auto k = SomeStruct(); t["fails"] = k; // Error: cannot create associative array T[string] // Segmentation fault } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 05 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4826 That should have been: void opIndexAssign(T)(T value, string key) if(is(T : SomeStruct)) { } But the error is the same either way. Bugzilla needs an edit button. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 05 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4826 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic Reduced test case: ---------- struct Struct4826 {} void bug4826(T)(T[string] value) {} void test4826() { bug4826(Struct4826()); } ---- This is closely related to bug 3996. The patch for bug 3996 removes the segfault, leaving only a useless error message with no line number, followed by a sensible error message with line number. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 06 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4826 Actually even with the patch for bug 3996, I found a test case which still segfaults: ------------ struct Struct4826 { } void bug4826b(T)(int[int] value) {} void test4826b() { bug4826b(Struct4826()); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 07 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4826 The segfault should be turned into an ICE by adding an extra assert into TypeAArray::getImpl(), in mtype.c 3967. + assert(ti->inst || sc); ti->semantic(sc); ti->semantic2(sc); ti->semantic3(sc); The problem is, that the template instance needs a scope (sc), but the scope is never set, so it remains NULL, causing a segfault when it is first used. I don't know how to solve this. I'm not even sure of what the scope should be. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 07 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4826 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch Summary|"cannot create associative |Regression(2.041) "cannot |array" and compiler crash |create associative array" | |and compiler crash Severity|normal |regression The original test case, and the one in comment 4, have slightly different causes. In comment 4, the problem is that AssociativeArray!() needs a scope, so that it can be instantiated. This is fixed by in the template.c patch. I believe that 'sc' is a correct scope, but I'm not certain. The original test case is fixed by the patch to mtype.c. It's just error suppression. Finally, I have a third test case which didn't even work on 2.040. This compiles when both patches are in place. ==================== void bug4826c(T)(int[int] value, T x) {} void test4826c() { AssociativeArray!(int, int) z; bug4826c(z,1); } ==================== // Type::deduceType(), template.c line 1920 if (ty != tparam->ty) + { + // Can't instantiate AssociativeArray!() without a scope + if (tparam->ty == Taarray && !((TypeAArray*)tparam)->sc) + ((TypeAArray*)tparam)->sc = sc; return implicitConvTo(tparam); + } // goto Lnomatch; if (nextOf()) return nextOf()->deduceType(sc, tparam->nextOf(), parameters, dedtypes); Lexact: return MATCHexact; -------------- Also: mtype.c, line 7000. MATCH TypeStruct::implicitConvTo(Type *to) { MATCH m; //printf("TypeStruct::implicitConvTo(%s => %s)\n", toChars(), to->toChars()); if (to->ty == Taarray) + { + // If there is an error instantiating AssociativeArray!(), it shouldn't + // be reported -- it just means implicit conversion is impossible. + ++global.gag; + int errs = global.errors; to = ((TypeAArray*)to)->getImpl()->type; + --global.gag; + if (errs != global.errors) + { global.errors = errs; + return MATCHnomatch; + } + } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 08 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4826 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla digitalmars.com Resolution| |FIXED 16:18:28 PDT --- http://www.dsource.org/projects/dmd/changeset/673 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 11 2010