From 141a4e290adeb3c08fae28423992a85e1001f867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sun, 24 Feb 2019 14:24:37 +0100 Subject: [PATCH] Detect types that are obviously not function literals. This avoids extremely cryptic error messages with no pointer to the origin of the problem. --- source/taggedalgebraic/taggedunion.d | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/taggedalgebraic/taggedunion.d b/source/taggedalgebraic/taggedunion.d index 0eb6181..3965caa 100644 --- a/source/taggedalgebraic/taggedunion.d +++ b/source/taggedalgebraic/taggedunion.d @@ -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); } }