1418 – tupleof bug on nested classes

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1418 - tupleof bug on nested classes
Summary: tupleof bug on nested classes
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
Reported: 2007年08月13日 06:07 UTC by ibrahim YANIKLAR
Modified: 2014年02月16日 15:24 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description ibrahim YANIKLAR 2007年08月13日 06:07:48 UTC
.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 Don 2010年07月28日 13:15:06 UTC
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 Walter Bright 2010年08月05日 23:39:40 UTC
http://www.dsource.org/projects/dmd/changeset/604 


AltStyle によって変換されたページ (->オリジナル) /