Skip to content

Commit

Permalink
fix issue 12064 - std.typecons.wrap doesn't handle NVI
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars-Kristiansen committed Nov 13, 2017
1 parent 5e41ddf commit c9f2158
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion std/typecons.d
Original file line number Diff line number Diff line change
Expand Up @@ -4684,16 +4684,24 @@ if (Targets.length >= 1 && allSatisfy!(isMutable, Targets))
alias type = F;
}

// issue 12064: Remove NVI members
template OnlyVirtual(members...)
{
enum notFinal(alias T) = !__traits(isFinalFunction, T);
alias OnlyVirtual = Filter!(notFinal, members);
}

// Concat all Targets function members into one tuple
template Concat(size_t i = 0)
{
static if (i >= Targets.length)
alias Concat = AliasSeq!();
else
{
alias Concat = AliasSeq!(GetOverloadedMethods!(Targets[i]), Concat!(i + 1));
alias Concat = AliasSeq!(OnlyVirtual!(GetOverloadedMethods!(Targets[i]), Concat!(i + 1)));
}
}

// Remove duplicated functions based on the identifier name and function type covariance
template Uniq(members...)
{
Expand Down Expand Up @@ -5059,6 +5067,32 @@ if (!isMutable!Target)
assert(i.bar(10) == 100);
}

@system unittest // issue 12064
{
interface I
{
int foo();
final int nvi1(){return foo();}
}

interface J
{
int bar();
final int nvi2(){return bar();}
}

class Baz
{
int foo() { return 42;}
int bar() { return 12064;}
}

auto baz = new Baz();
auto foobar = baz.wrap!(I, J)();
assert(foobar.nvi1 == 42);
assert(foobar.nvi2 == 12064);
}

// Make a tuple of non-static function symbols
package template GetOverloadedMethods(T)
{
Expand Down

0 comments on commit c9f2158

Please sign in to comment.