From a3078c34fcf2ca110541bf696d9a86204d15a015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 4 Apr 2020 15:15:53 +0200 Subject: [PATCH] Fix another compile error related to generic visitors. --- source/taggedalgebraic/visit.d | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/source/taggedalgebraic/visit.d b/source/taggedalgebraic/visit.d index 46e9086..7310018 100644 --- a/source/taggedalgebraic/visit.d +++ b/source/taggedalgebraic/visit.d @@ -128,6 +128,21 @@ unittest { //static assert(!is(typeof(u.visit!((int) {}, (float) {}, () {}, (_) {})))); // superfluous generic handler } +unittest { + // make sure that the generic handler is not instantiated with types for + // which it doesn't compile + class C {} + union U { int i; C c; } + TaggedUnion!U u; + u.visit!( + (C c) => c !is null, + (v) { + static assert(is(typeof(v) == int)); + return v != 0; + } + ); +} + /** The same as `visit`, except that failure to handle types is checked at runtime. @@ -258,7 +273,7 @@ private template selectHandler(T, VISITORS...) static if (i < VISITORS.length) { alias fun = VISITORS[i]; static if (!isSomeFunction!fun) { - static if (isSomeFunction!(fun!T)) { + static if (__traits(compiles, fun!T) && isSomeFunction!(fun!T)) { static if (ParameterTypeTuple!(fun!T).length == 1) { static if (matched_index >= 0) enum genericIndex = "Only one generic visitor allowed"; else enum genericIndex = genericIndex!(i+1, i);