Merge pull request #27 from s-ludwig/detect_invalid_visitors

Detect types that are obviously not function literals.
This commit is contained in:
Sönke Ludwig 2019-02-24 15:00:34 +01:00 committed by GitHub
commit aa6b78783e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -546,11 +546,15 @@ enum isUnitType(T) = is(T == Void) || is(T == void) || is(T == typeof(null));
private template validateHandlers(TU, VISITORS...)
{
import std.traits : isSomeFunction;
alias Types = TU.FieldTypes;
static foreach (int i; 0 .. VISITORS.length) {
static assert(!is(VISITORS[i]) || isSomeFunction!(VISITORS[i]),
"Visitor at index "~i.stringof~" must be a function/delegate literal: "~VISITORS[i].stringof);
static assert(anySatisfy!(matchesType!(VISITORS[i]), Types),
"Visitor at index "~i.stringof~" does not match any type of "~TU.stringof);
"Visitor at index "~i.stringof~" does not match any type of "~TU.FieldTypes.stringof);
}
}