Jump to page: 1 2
Thread overview
[Issue 5868] New: static attribute ignored with public static {} blocks
Apr 21, 2011
Mike Parker
Apr 21, 2011
Don
Jan 26, 2012
Walter Bright
Jan 27, 2012
Walter Bright
Jan 27, 2012
Jonathan M Davis
Jan 28, 2012
Jonathan M Davis
Jan 28, 2012
yebblies
April 21, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5868

           Summary: static attribute ignored with public static {} blocks
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: aldacron@gmail.com


--- Comment #0 from Mike Parker <aldacron@gmail.com> 2011-04-21 05:35:39 PDT ---
The following produces an error for conflicting constructors, "Previous Definition Different".

class Foo
{
    public static
    {
        this() {}
    }

    public
    {
        this() {}
    }
}

Remove the curly braces from the public static and it compiles fine. With anything defined or declared in a public static block, the static attribute is ignored. I'm sure this used to work, once upon a time. Tested on 2.052 only.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 21, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5868


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #1 from Don <clugdbug@yahoo.com.au> 2011-04-21 05:51:27 PDT ---
(In reply to comment #0)
> The following produces an error for conflicting constructors, "Previous Definition Different".

> I'm sure this used to work, once upon a time.
No. It failed even on DMD 0.140 (Nov 2005).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 26, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5868


hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx


--- Comment #2 from hsteoh@quickfur.ath.cx 2012-01-26 10:27:46 PST ---
This bug also happens without "public" for static ctors:

class A {
    static {
        int x;    // this is OK, interpreted as "static int x"
        this() { ... } // this is NOT OK, interpreted as non-static this()
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 26, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5868


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |INVALID


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2012-01-26 12:28:27 PST ---
Not a bug. Spec sez:

"The static in the static constructor declaration is not an attribute, it must appear immediately before the this"

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 26, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5868



--- Comment #4 from hsteoh@quickfur.ath.cx 2012-01-26 12:35:32 PST ---
So the right syntax is:

class A {
    static {
        ...
        static this() { ... }
        ...
    }
}

?

Or alternatively

class A {
    static { ... }
    static this() { ... }
}

?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 26, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5868


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #5 from bearophile_hugs@eml.cc 2012-01-26 13:41:06 PST ---
(In reply to comment #3)
> Not a bug. Spec sez:
> 
> "The static in the static constructor declaration is not an attribute, it must appear immediately before the this"

Then is it better for the compiler to give an compile-time error for code like this? Is this material for a diagnostic enhancement request?


class A {
    static {
        this() { ... }
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5868



--- Comment #6 from Walter Bright <bugzilla@digitalmars.com> 2012-01-26 17:19:02 PST ---
I don't think there's anything wrong with the current setup.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5868



--- Comment #7 from hsteoh@quickfur.ath.cx 2012-01-26 17:44:20 PST ---
There's nothing technically wrong with it, but it's misleading. When you write:

class A {
    int x;
    this(int) { ... }

    static {
        int y;
        this(uint) { ... }
    }
}

It appears as though the second ctor is somehow "static" in some sense, yet it is not, as the current semantics mean that you can hoist it out of the static block and still retain the same meaning. Since that's the case, why not prohibit it from being placed in a static block in the first place?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5868


Jonathan M Davis <jmdavisProg@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg@gmx.com


--- Comment #8 from Jonathan M Davis <jmdavisProg@gmx.com> 2012-01-26 17:50:01 PST ---
Invalid attributes are usually ignored in D rather than resulting in an error. So, it's quite consistent that if static {} has no effect on a constructor, the compiler wouldn't complain about you putting a constructor within the static block. Now, whether it's _desirable_ that D function that way is another matter - in general, IMHO it's definitely a negative that invalid attributes get ignored rather than resulting in errors - but it's definitely consistent with the rest of the language.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 27, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=5868



--- Comment #9 from bearophile_hugs@eml.cc 2012-01-26 18:07:08 PST ---
(In reply to comment #7)
> There's nothing technically wrong with it, but it's misleading.

I think here there's material for a diagnostic enhancement request.


(In reply to comment #8)
> Invalid attributes are usually ignored in D rather than resulting in an error.

And this is so wrong that it must change. I have zero doubts about this.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2