www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15477] New: Forward reference error corner case with base

https://issues.dlang.org/show_bug.cgi?id=15477

          Issue ID: 15477
           Summary: Forward reference error corner case with base class
                    and template specialization arguments
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: syniurge gmail.com

Related to issue 12152, there are still bogus forward reference errors.

class QObjectPrivate : QObjectData
{
    struct Sender
    {
        void *sender;
        int signal;
        int ref_;
    }
}

class QObjectData
{
    uint o;
    QTypeInfo!uint ti;
}

struct QTypeInfo(T : uint)
{
    immutable string info = "a";
}

struct QTypeInfo(T : QObjectPrivate.Sender)
{
    immutable string info = "b";
}
-----
Error: class main.QObjectPrivate is forward referenced when looking for
'Sender'

The order of declaration matters, if the base class QObjectData is declared
before QObjectPrivate then it compiles fine. So the workaround is simple if you
can just modify the code, but this happens with Qt5 mapped by Calypso where
this isn't an option.

What happens is:
1/ ClassDeclaration::semantic() on QObjectPrivate tries to run semantic() on
the base class QObjectData
2/ semantic() on QObjectData calls semantic() on the template instance
QTypeInfo!uint
3/ TemplateInstance::findTempDecl() attempts to semantic() the specialization
arguments of all the QTypeInfo overloads

But for the QObjectPrivate.Sender one, ClassDeclaration::search("Sender") fails
because the ClassDeclaration for QObjectPrivate doesn't have a symtab yet.

Moving the fix for issue 12152
(https://github.com/D-Programming-Language/dmd/pull/4469) to before
semantic'ing the base classes seems to fix it.


However this may not be the right way to see it.
ClassDeclaration::search("Sender") fails also because ->scope was set to NULL
at the beginning of ClassDeclaration::semantic on QObjectPrivate so search()
doesn't call semantic(). I haven't tested but that second call should work and
populate the symtab if it doesn't re-go through semantic() on the base class
(but at this point ->scope is also null for QObjectData so it won't). Anyway
simply moving the symtab populating seems like the simplest fix.

--
Dec 24 2015