[Issue 4962] New: Improve error message for wrong constructor name?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 30 13:14:35 PDT 2010


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 at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2010-09-30 13:14:17 PDT ---
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: -------


More information about the Digitalmars-d-bugs mailing list