Skip to content

Commit

Permalink
Merge pull request #5858 from BBasile/issue-12064
Browse files Browse the repository at this point in the history
fix issue 12064 - std.typecons.wrap doesn't handle NVI
merged-on-behalf-of: MetaLang <MetaLang@users.noreply.github.com>
  • Loading branch information
dlang-bot authored Nov 14, 2017
2 parents 0308bd6 + c9f2158 commit d1a0a32
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 d1a0a32

Please sign in to comment.