← Back to index
|
Original Bugzilla link
Bug 6895 – std.traits.isCovariantWith doesn't work for function, function pointer and delegate
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-11-05T09:25:56Z
Last change time
2017-12-18T22:55:39Z
Keywords
bootcamp, patch
Assigned to
Alexandru Razvan Caciulescu
Creator
Haruki Shigemori
Comments
Comment #0
by rayerd.wiz — 2011-11-05T09:25:56Z
diff --git a/std/traits.d b/std/traits.d index 1b02d12..d24f1fc 100644 --- a/std/traits.d +++ b/std/traits.d @@ -2345,7 +2345,9 @@ static assert(isCovariantWith!(typeof(C.clone), typeof(J.clone))); -------------------- */ 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; @@ -2471,6 +2473,15 @@ unittest static assert(isCovariantWith!(BaseA.test, BaseA.test)); 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); }
Comment #1
by alexandru.razvan.c — 2017-10-24T12:50:30Z
https://github.com/dlang/phobos/pull/5800
Comment #2
by github-bugzilla — 2017-10-24T14:09:37Z
Commits pushed to master at
https://github.com/dlang/phobos
https://github.com/dlang/phobos/commit/1d26b5fef7ff33b51f0d26898f555727278b351b
Fix issue 6895 std.traits.isCovariantWith doesn't work for function, function pointer and delegate
https://github.com/dlang/phobos/commit/3f34eefe9a15504598f91e690b0e722981c0a83f
Merge pull request #5800 from Darredevil/issue-6895-covariance Fix issue 6895 std.traits.isCovariantWith doesn't work for function, … merged-on-behalf-of: Andrei Alexandrescu <
[email protected]
>
Comment #3
by github-bugzilla — 2017-12-18T22:55:39Z
Commits pushed to stable at
https://github.com/dlang/phobos
https://github.com/dlang/phobos/commit/1d26b5fef7ff33b51f0d26898f555727278b351b
Fix issue 6895 std.traits.isCovariantWith doesn't work for function, function pointer and delegate
https://github.com/dlang/phobos/commit/3f34eefe9a15504598f91e690b0e722981c0a83f
Merge pull request #5800 from Darredevil/issue-6895-covariance