Bug 1418 – tupleof bug on nested classes

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2007-08-13T06:07:00Z
Last change time
2014-02-16T15:24:19Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
yanikibo

Comments

Comment #0 by yanikibo — 2007-08-13T06:07:48Z
.tupleof accesses an extra (unknown) member on nested classes. The following example shows this bug on dmd 1.020 and 2.003, also gdc gives a similar result --- main.d --- import std.stdio; class A { char name = 'A'; class B { char name = 'B'; } } void main() { class C { char name = 'C'; } A a = new A; a.B b = a.new B; C c = new C; writefln(a.tupleof); // prints: A writefln(b.tupleof); // prints: B main.A writefln(c.tupleof); // prints: C 0000 }
Comment #1 by clugdbug — 2010-07-28T13:15:06Z
tupleof shouldn't be including hidden 'this' members. PATCH: mtype.c, line 7138, TypeClass::dotExp() if (ident == Id::tupleof) { /* Create a TupleExp */ e = e->semantic(sc); // do this before turning on noaccesscheck Expressions *exps = new Expressions; exps->reserve(sym->fields.dim); for (size_t i = 0; i < sym->fields.dim; i++) { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i]; + // Don't include hidden 'this' pointer + if (v->isThisDeclaration()) + continue; Expression *fe = new DotVarExp(e->loc, e, v); exps->push(fe); } e = new TupleExp(e->loc, exps); sc = sc->push(); sc->noaccesscheck = 1; e = e->semantic(sc); sc->pop(); return e; }
Comment #2 by bugzilla — 2010-08-05T23:39:40Z