Jump to page: 1 2 3
Thread overview
[Issue 3075] New: void delegate(const(void)[]) should be implicitly convertable to void delegate(void[])
Jun 17, 2009
davidl@126.com
Jul 02, 2009
Sobirari Muhomori
Jul 03, 2009
Walter Bright
Jul 03, 2009
Walter Bright
Jul 03, 2009
Walter Bright
Jul 03, 2009
Walter Bright
Jul 03, 2009
david
Jul 03, 2009
Walter Bright
Jul 03, 2009
david
Jul 04, 2009
Walter Bright
Jul 09, 2009
Walter Bright
Jul 09, 2009
Walter Bright
Jul 09, 2009
Walter Bright
Jul 10, 2009
Sobirari Muhomori
Jul 10, 2009
Sobirari Muhomori
Jul 10, 2009
Sobirari Muhomori
Jul 13, 2009
Sobirari Muhomori
Jul 13, 2009
Sobirari Muhomori
Jul 13, 2009
Sobirari Muhomori
Jun 16, 2011
yebblies
June 17, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3075

           Summary: void delegate(const(void)[]) should be implicitly
                    convertable to void delegate(void[])
           Product: D
           Version: 2.028
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: davidl@126.com


It's perfectly safe to call a const/invariant ensured version delegate or function when the caller only try to call a version without any const warranties.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 02, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3075


Sobirari Muhomori <maxmo@pochta.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |2267




--- Comment #1 from Sobirari Muhomori <maxmo@pochta.ru>  2009-07-02 06:47:55 PDT ---
Is it tango2 blocker? There is a tracker for tango2 blockers - bug 2267.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 03, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3075


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com




--- Comment #2 from Walter Bright <bugzilla@digitalmars.com>  2009-07-02 19:27:02 PDT ---
A test case:

void foo(void delegate(void[]) dg);

void test()
{
    void func(const(void)[] t)
    {
    }

    foo(&func);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 03, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3075





--- Comment #3 from Walter Bright <bugzilla@digitalmars.com>  2009-07-03 00:51:57 PDT ---
const, yes, but not immutable as that would require that mutable be implicitly convertible to immutable, which cannot be.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 03, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3075


Walter Bright <bugzilla@digitalmars.com> changed:

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




--- Comment #4 from Walter Bright <bugzilla@digitalmars.com>  2009-07-03 01:09:32 PDT ---
The actual rule for matching a delegate against a type is that the delegate is covariant with the type. The return type is checked for covariance, and things like a pure function is considered covariant with an impure one. This works exactly the same as overriding a virtual function with a covariant one.

What you're asking for with the const parameters is contravariance. Contravariant parameters are a good idea until overloading is considered. If you have two functions, one with a const parameter and the other mutable, which one overrides the base virtual function? You could say overriding is based on a 'best match', but things are complex enough without throwing that into the mix.

So, it is by design that the parameter lists must match exactly for covariant functions. I also think it is not a good idea to have one covariant matching rule for overriding, and another for implicit conversions. Better to have one covariant rule.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 03, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3075


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |INVALID




-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 03, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3075


david <davidl@126.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |




--- Comment #5 from david <davidl@126.com>  2009-07-03 07:56:21 PDT ---
(In reply to comment #3)
> const, yes, but not immutable as that would require that mutable be implicitly convertible to immutable, which cannot be.

It's not implicit cast. But a special case for function/delegate parameters.

Any qualifier for parameters or for the function is a restriction for the function. So you can still treat them as a special case of mutable version just they don't change anything even they are allowed to change the parameter.


This is another testcase. void foo(void delegate(void[]) dg);

void test()
{
    void func(invariant(void)[] t)
    {
    }

    foo(&func);
}

test.func won't change paramter t. So this func as a delegate is perfectly safe to hold the prototype which has no restrictions on parameters.

It's not casting invariant(void)[] to void[]. It's implicitly casting from
"void delegate(invariant(void)[])" to "void delegate(void[])".

Furthermore, it's pretty ugly to write:
void foo(void delegate(void[]) dg);

void test()
{
    void func(invariant(void)[] t)
    {
    }

    foo(cast(void delegate(void[]))&func);
}

I don't think it is an invalid bug. But you can mark it as WONTFIX.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 03, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3075


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |INVALID




--- Comment #6 from Walter Bright <bugzilla@digitalmars.com>  2009-07-03 10:55:57 PDT ---
It is an implicit cast. First, the invariant of course won't change the arguments. The problem is that the function that takes the invariant assumes that the data is invariant, i.e. never changes. Mutable data that is implicitly cast to invariant *can* change (because mutable aliases for the same data may exist). Therefore, a function taking an invariant is *not* compatible with a function taking a mutable.

For the disposition, INVALID means that the compiler works as designed, which it does in this case. The WONTFIX still means the compiler is not working as designed, which is not the case here. Hence, the INVALID disposition is the correct one.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 03, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3075





--- Comment #7 from david <davidl@126.com>  2009-07-03 16:47:11 PDT ---
(In reply to comment #3)
> const, yes, but not immutable as that would require that mutable be implicitly convertible to immutable, which cannot be.

wait, but you are going to fix the const one?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 04, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=3075





--- Comment #8 from Walter Bright <bugzilla@digitalmars.com>  2009-07-03 18:24:55 PDT ---
No, for the reasons already mentioned.

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