Avoid instantiating generic visitor with types it cannot handle.
In cases where statically typed visitors need to be defined to avoid compile errors in a generic visitor, the generic one was still instantiated with the types already handled by the statically typed one(s), possibly resulting in a compile error.
This commit is contained in:
parent
f9eb5878ad
commit
7a6da0ff79
|
@ -217,7 +217,7 @@ private template matchesType(alias fun) {
|
|||
else static if (Params.length == 1 && is(T == Params[0])) enum matchesType = true;
|
||||
else enum matchesType = false;
|
||||
} else static if (!isUnitType!T) {
|
||||
static if (isSomeFunction!(fun!T)) {
|
||||
static if (__traits(compiles, fun!T) && isSomeFunction!(fun!T)) {
|
||||
alias Params = ParameterTypeTuple!(fun!T);
|
||||
static if (Params.length == 1 && is(T == Params[0])) enum matchesType = true;
|
||||
else enum matchesType = false;
|
||||
|
@ -226,6 +226,16 @@ private template matchesType(alias fun) {
|
|||
}
|
||||
}
|
||||
|
||||
unittest {
|
||||
class C {}
|
||||
alias mt1 = matchesType!((C c) => true);
|
||||
alias mt2 = matchesType!((c) { static assert(!is(typeof(c) == C)); });
|
||||
static assert(mt1!C);
|
||||
static assert(!mt1!int);
|
||||
static assert(mt2!int);
|
||||
static assert(!mt2!C);
|
||||
}
|
||||
|
||||
private template selectHandler(T, VISITORS...)
|
||||
{
|
||||
import std.traits : ParameterTypeTuple, isSomeFunction;
|
||||
|
|
Loading…
Reference in a new issue