--- Comment #2 from david <>  2009-07-03 16:33:30 PDT ---
(In reply to comment #1)
> No.  This is working as intended.  What you're doing here is shadowing the
> global 'c' with a local 'c'.  Symbol lookup in D is simple: it looks in
> enclosing scopes until it finds a symbol of the given name, no matter how
> you're using that name.  If you're porting code from another language, you're
> going to have to expect some translation work.  And besides, what's so
> difficult about "c c = new c;", or better yet, _not doing it in the first
> place_?

c c = new c; <-- this is the only 1 case that trigger this issue.
Sometimes you can have

class ClassType1

class ClassType2
  ClassType1 ClassType1;
  void func(ClassType1 t){} // this ClassType1 is clearly referring to the type
of "ClassType1"

And it's not hard to make this work. I see no reason to ignore this one.

My own dmd gets several other features patched. So it's somewhat troublesome to
isolate the patch to this particular bug.

The idea is pretty simple, when you try to tell the user the error, firstly try
to resolve the type upper scope

A roughly patch:

Type *TypeIdentifier::semantic(Loc loc, Scope *sc)
    Type *t;
    Expression *e;
    Dsymbol *s;
+++    bool tried = false;
+++    Scope *sce = sc -> enclosing;

    //printf("TypeIdentifier::semantic(%s)\n", toChars());
    resolve(loc, sc, &e, &t, &s);
+++ L1:    
    if (t)
    //printf("\tit's a type %d, %s, %s\n", t->ty, t->toChars(), t->deco);

    if (t->ty == Ttypedef)
    {   TypeTypedef *tt = (TypeTypedef *)t;

        if (tt->sym->sem == 1)
        error(loc, "circular reference of typedef %s", tt->toChars());
    t = t->addMod(mod);
+++            if ( sce != NULL)
+++            {
+++                resolve(loc, sce, &e, &t, &s);
+++                sce = sce -> enclosing;
+++                goto L1;
+++            }

#ifdef DEBUG
    if (!global.gag)
        printf("1: ");
    if (s)
        s->error(loc, "is used as a type");
        error(loc, "%s is used as a type", toChars());
    t = tvoid;
    return t;

You see, it's simple. I think it should be enhanced.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to