mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 06:00:35 +03:00
Fix issue 6895 std.traits.isCovariantWith doesn't work for function, function pointer and delegate
This commit is contained in:
parent
2d2592f538
commit
1d26b5fef7
1 changed files with 12 additions and 1 deletions
13
std/traits.d
13
std/traits.d
|
@ -4885,7 +4885,9 @@ Determines whether the function type $(D F) is covariant with $(D G), i.e.,
|
|||
functions of the type $(D F) can override ones of the type $(D G).
|
||||
*/
|
||||
template isCovariantWith(F, G)
|
||||
if (is(F == function) && is(G == function))
|
||||
if (is(F == function) && is(G == function) ||
|
||||
is(F == delegate) && is(G == delegate) ||
|
||||
isFunctionPointer!F && isFunctionPointer!G)
|
||||
{
|
||||
static if (is(F : G))
|
||||
enum isCovariantWith = true;
|
||||
|
@ -5031,6 +5033,15 @@ template isCovariantWith(F, G)
|
|||
static assert( isCovariantWith!(DerivA_1.test, DerivA_1.test));
|
||||
static assert( isCovariantWith!(DerivA_2.test, DerivA_2.test));
|
||||
|
||||
// function, function pointer and delegate
|
||||
J function() derived_function;
|
||||
I function() base_function;
|
||||
J delegate() derived_delegate;
|
||||
I delegate() base_delegate;
|
||||
static assert(.isCovariantWith!(typeof(derived_function), typeof(base_function)));
|
||||
static assert(.isCovariantWith!(typeof(*derived_function), typeof(*base_function)));
|
||||
static assert(.isCovariantWith!(typeof(derived_delegate), typeof(base_delegate)));
|
||||
|
||||
// scope parameter
|
||||
interface BaseB { void test( int*, int*); }
|
||||
interface DerivB_1 : BaseB { override void test(scope int*, int*); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue