[Issue 340] New: [Tracker] Forward reference bugs and other order-of-declaration issues

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 10 10:11:16 PDT 2006


http://d.puremagic.com/issues/show_bug.cgi?id=340

           Summary: [Tracker] Forward reference bugs and other order-of-
                    declaration issues
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: smjg at iname.com
        ReportedBy: smjg at iname.com
 BugsThisDependsOn: 52,102,104,190,235,275,339


A design principle of D is that the order of declarations at module level or
class level is irrelevant.

Here's just one statement to this effect:

[Features to Drop]
"Forward declarations. C compilers semantically only know about what has
lexically preceded the current state. C++ extends this a little, in that class
members can rely on forward referenced class members. D takes this to its
logical conclusion, forward declarations are no longer necessary at the module
level. Functions can be defined in a natural order rather than the typical
inside-out order commonly used in C programs to avoid writing forward
declarations."

(There ought to be more, but I can't seem to find them at the moment.)

As such, there should be no errors reported by the compiler caused by trying to
use a symbol before it's defined.  Of course it makes sense that a variable
can't be used within a function before it's declared, with functions being
sequential in nature.  But otherwise, the compiler should accept forward
references without any trouble.

There are two documented instances for which forward references fail, namely
nested functions within a function and autotype declarations.  Otherwise, any
failures of a D compiler to get over the fact that the use of a symbol
lexically precedes its declaration in a module, class, etc. are bugs.

While we're at it, forward reference bugs are part of a more general class of
issues whereby the compiler treats code differently depending on the lexical
order of declarations.  These can include not only valid code failing to
compile, but also instances where the code compiles either way but behaves
differently.

This is a tracker for bugs of this nature - bugs whereby code containing
forward references fails to compile correctly, and anywhere else where the
order of declarations influences compiler behaviour in a way that should not be
happening.

Getting the phrase "forward referenced" out of the compiler's repertoire of
error messages (by actually fixing the bugs, obviously, not by rewording the
error) would certainly be a step forward.


-- 




More information about the Digitalmars-d-bugs mailing list