www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4962] New: Improve error message for wrong constructor name?

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4962

           Summary: Improve error message for wrong constructor name?
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This is born from a post in D.learn:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=22040

In code written by D programmers coming from C++ or some other languages, or in
D code translated from other languages, constructors may have the same name of
the struct/union/class (it's a bug):


struct Foo {
     Foo(int x_) {}
}
void main() {}


DMD 2.049 prints (similar errors are produced if Foo is a class or union):

test.d(2): found 'int' when expecting ')'
test.d(2): no identifier for declarator Foo
test.d(2): semicolon expected, not 'x_'
test.d(2): no identifier for declarator x_
test.d(2): semicolon expected, not ')'
test.d(2): Declaration expected, not ')'
test.d(5): } expected following member declarations in aggregate


In this situation it's positive to give a single error message that is more
easy to understand. To do this well I think DMD has to essentially recognize
that as a Java-style constructor syntax, and refuse it, with a single error
similar to:

test.d(3): class/struct/union constructors are always named 'this' not 'Foo'.

But I am not sure, because the creation of such test may have some negative
side effects. If such side effects are too much bad, then it's better to not
add this test and error message and it's better to close this enhancement
request.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 30 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4962


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



With DMD 2.050 that program gives the following error messages, that while not
being perfect, are good enough, so I close this enhancement request:


test.d(2): function declaration without return type. (Note that constructors
are always named 'this')
test.d(2): no identifier for declarator Foo(int x_)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 01 2010