From 1d26b5fef7ff33b51f0d26898f555727278b351b Mon Sep 17 00:00:00 2001 From: Alexandru Caciulescu Date: Tue, 24 Oct 2017 15:48:53 +0300 Subject: [PATCH] Fix issue 6895 std.traits.isCovariantWith doesn't work for function, function pointer and delegate --- std/traits.d | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/std/traits.d b/std/traits.d index ce555f4daaa..2d812ee77ac 100644 --- a/std/traits.d +++ b/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*); }