Skip to content

Commit

Permalink
Merge pull request #5800 from Darredevil/issue-6895-covariance
Browse files Browse the repository at this point in the history
Fix issue 6895 std.traits.isCovariantWith doesn't work for function, …
merged-on-behalf-of: Andrei Alexandrescu <andralex@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Oct 24, 2017
2 parents e5a146b + 1d26b5f commit 3f34eef
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion std/traits.d
Expand Up @@ -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;
Expand Down Expand Up @@ -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*); }
Expand Down

0 comments on commit 3f34eef

Please sign in to comment.