[Issue 3075] Implement parameter contravariance

2024-07-03 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3075

--- Comment #32 from Bolpat  ---
Good:
```d
void main()
{
void function(const(int)*) fp = null;
void function(  int *) gp = fp;
void function(immutable(int)*) hp = fp;
}
```

Error:
```d
void main()
{
void function(ref const int ) fp = null;
void function(ref   int ) gp = fp; // error
void function(ref immutable(int)) hp = fp; // error
}
```

Same with s/function/delegate/g.

--


[Issue 3075] Implement parameter contravariance

2022-12-17 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3075

Iain Buclaw  changed:

   What|Removed |Added

   Priority|P2  |P4

--


[Issue 3075] Implement parameter contravariance

2021-01-09 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3075

--- Comment #31 from Bolpat  ---
In the context of Argument-dependent Attributes (ADA) or Attributes for
Higher-Order Functions (AfHOF) (pending DIPs), contravariant overloading is
necessary. Imagine a proper sink-toString interface. The whole reason to have a
sink in the first place instead of returning an allocated string is not doing
the allocation.

So, considering

  interface SinkToString
  {
  void toString(scope void delegate(char) @nogc) @nogc;
  }

the following override should work in some way:

  class C : SinkToString
  {
  override(scope void delegate(char) @nogc)
  void toString(in void delegate(char) sink) @nogc const
  { ... }
  }

The intention of the interface is: toString is @nogc and may require a @nogc
delegate for this.
An implementation of it may not require a @nogc delegate in its internal logic,
but by the reasoning explained in AfHOF, calling C.toString with a @nogc
argument will result in a @nogc execution. ADA is similar (as far as I can
tell): one would replace the @nogc of C.toString by @nogc(*).

--


[Issue 3075] Implement parameter contravariance

2021-01-09 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3075

Bolpat  changed:

   What|Removed |Added

 CC||qs.il.paperi...@gmail.com

--- Comment #30 from Bolpat  ---
Overriding with contravariant parameter types can work.
Because D has overloading and contravariant overriding is factually
indistinguishable from overloading, an annotation must be used to clarify:

It could be as simple as giving override an optional type list that signifies
the types of the parameters of the method to be overridden:

Attribute:
...
override
+   override Parameters

class X {}
class Y : X {}

class C
{
  void foo(Y y) {}
}

class D : C
{
  override(Y) void foo(X x) {} // overrides foo(Y y)
}

It's similar to the VisibilityAttribute package with a QualifiedIdentifier to
signify the exact package it should be visible from. It's very specific and one
could argue that overloading and forwarding solves the issue in almost all
cases.

class D : C
{
  override void foo(Y y) { foo(cast(X) y); }
  void foo(X x) { ... }
}

There might be very specific circumstances where this is not a viable option.

--


[Issue 3075] Implement parameter contravariance

2019-09-27 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3075

RazvanN  changed:

   What|Removed |Added

 CC||razvan.nitu1...@gmail.com

--- Comment #29 from RazvanN  ---
(In reply to Walter Bright from comment #2)
> A test case:
> 
> void foo(void delegate(void[]) dg);
> 
> void test()
> {
> void func(const(void)[] t)
> {
> }
> 
> foo();
> }

This test case compiles today. Is this issue fixed?

--


[Issue 3075] Implement parameter contravariance

2017-05-09 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3075

Walter Bright  changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
 Resolution|INVALID |---

--- Comment #28 from Walter Bright  ---
Reopened because contravariance really should work.

--


[Issue 3075] Implement parameter contravariance

2017-05-09 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3075

Walter Bright  changed:

   What|Removed |Added

   See Also||https://issues.dlang.org/sh
   ||ow_bug.cgi?id=17349

--


[Issue 3075] Implement parameter contravariance

2017-05-09 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3075

Walter Bright  changed:

   What|Removed |Added

   See Also||https://issues.dlang.org/sh
   ||ow_bug.cgi?id=16303

--


[Issue 3075] Implement parameter contravariance

2015-06-09 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3075

Andrei Alexandrescu and...@erdani.com changed:

   What|Removed |Added

Version|2.028   |D2

--


[Issue 3075] Implement parameter contravariance

2013-12-19 Thread d-bugmail
https://d.puremagic.com/issues/show_bug.cgi?id=3075


Denis Shelomovskij verylonglogin@gmail.com changed:

   What|Removed |Added

 CC||verylonglogin@gmail.com


--- Comment #27 from Denis Shelomovskij verylonglogin@gmail.com 
2013-12-19 22:26:21 MSK ---
*** Issue 11773 has been marked as a duplicate of this issue. ***

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