Thread overview
[Issue 21538] Overriding with more attributes on delegate parameter is allowed
Jan 10, 2021
Bolpat
Jan 10, 2021
Bolpat
Jan 27, 2021
RazvanN
Jan 27, 2021
Dlang Bot
Mar 31, 2021
Bolpat
Nov 05, 2021
Dlang Bot
Nov 13, 2021
Dlang Bot
January 10, 2021
https://issues.dlang.org/show_bug.cgi?id=21538

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid, safe

--- Comment #1 from Bolpat <qs.il.paperinik@gmail.com> ---
DMD rejected the override from version 2.066 to 2.074.1; the regression affects DMD since 2.075.1.

Just to prove that the cast and the actual delegate isn't the issue, the following compiles, too:

    auto dg = delegate() @system { int* p; int x; p = &x; }; // unsafe actions
    I i = new C;
    i.f(dg); // okay, unexpeced

It works with function pointers, too:

    auto fp = () @system { int* p; int x; p = &x; };
    i.g(fp);

--
January 10, 2021
https://issues.dlang.org/show_bug.cgi?id=21538

Bolpat <qs.il.paperinik@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qs.il.paperinik@gmail.com

--
January 27, 2021
https://issues.dlang.org/show_bug.cgi?id=21538

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #2 from RazvanN <razvan.nitu1305@gmail.com> ---
>From spec [1]: "A function in a derived class with the same name and covariant
with a function in a base class overrides that function". Also, [2] (point 8) defines covariance: "A covariant function has a type that is implicitly convertible to the type of the overridden function.". Finally, [3] (point 6) shows that @safe functions are covariant with @system functions.

PR that explicitly introduced this: https://github.com/dlang/dmd/pull/6731 .

I think that this case was simply overlooked. Functions that implement interface functions should match exactly.

[1] https://dlang.org/spec/function.html#function-inheritance [2] https://dlang.org/spec/function.html#virtual-functions [3] https://dlang.org/spec/function.html#safe-functions

--
January 27, 2021
https://issues.dlang.org/show_bug.cgi?id=21538

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
@RazvanN7 created dlang/dmd pull request #12160 "Fix Issue 21538 - Overriding with more attributes on delegate parameter is allowed" fixing this issue:

- Fix Issue 21538 - Overriding with more attributes on delegate parameter is allowed

https://github.com/dlang/dmd/pull/12160

--
March 31, 2021
https://issues.dlang.org/show_bug.cgi?id=21538

--- Comment #4 from Bolpat <qs.il.paperinik@gmail.com> ---
*** Issue 21602 has been marked as a duplicate of this issue. ***

--
November 05, 2021
https://issues.dlang.org/show_bug.cgi?id=21538

moonlightsentinel@disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eyal@weka.io

--- Comment #5 from moonlightsentinel@disroot.org ---
*** Issue 20409 has been marked as a duplicate of this issue. ***

--
November 05, 2021
https://issues.dlang.org/show_bug.cgi?id=21538

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
@MoonlightSentinel created dlang/dmd pull request #13267 "Fix 21538,20904: Correct implicitConvTo order for delegate parameters in `Type.covariant`" fixing this issue:

- Fix 21538,20904: Correct implicitConvTo order for delegate parameters...

  ... in `Type.covariant`

  The ordering was inversed when compared to function pointers. That caused
  the check to accept e.g. less restrictive attributes for callbacks.

  Also changed the equality checks for `TypeFuntion` and `TypeDelegate`
  to `equals` because `==` didn't call the former and hence caused problems
  for duplicate instances.

https://github.com/dlang/dmd/pull/13267

--
November 13, 2021
https://issues.dlang.org/show_bug.cgi?id=21538

Dlang Bot <dlang-bot@dlang.rocks> changed:

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

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #13267 "Fix 21538,20904: Correct implicitConvTo order for delegate parameters in `Type.covariant`" was merged into master:

- f81a1ccaeb0aa3d5575332ceeca4280b5c585d7d by MoonlightSentinel:
  Fix 21538,20904: Correct implicitConvTo order for delegate parameters...

  ... in `Type.covariant`

  The ordering was inversed when compared to function pointers. That caused
  the check to accept e.g. less restrictive attributes for callbacks.

  Also changed the equality checks for `TypeFuntion` and `TypeDelegate`
  to `equals` because `==` didn't call the former and hence caused problems
  for duplicate instances.

https://github.com/dlang/dmd/pull/13267

--