https://dlang.org/phobos/std_variant.html#.visit it said: > If a function with an untyped parameter is specified, this function is called when the variant contains a type that does not match any other function. This can be used to apply the same function across multiple possible types. Exactly one generic function is allowed. but this doesn't work: --- > dmd --version DMD32 D Compiler v2.091.0-beta.2-master-ec39fe5 > dmd code.d -vcolumns code.d(7,15): Error: no property n for type code.B ...\variant.d(2293,55): instantiated from here: visitImpl!(true, VariantN!(4u, A, B), function (B _) pure nothrow @nogc @safe => 42, (a) => a.n) code.d(5,21): instantiated from here: visit!(VariantN!(4u, A, B)) ...\variant.d(2562,21): Error: static assert: "__lambda2 is not a function or delegate" ...\variant.d(2293,55): instantiated from here: visitImpl!(true, VariantN!(4u, A, B), function (B _) pure nothrow @nogc @safe => 42, (a) => a.n) code.d(5,21): instantiated from here: visit!(VariantN!(4u, A, B)) > type code.d import std; void main() { Algebraic!(A, B)().visit!( (B _) => 42, (a ) => a.n ); } struct A{int n;} struct B{ } ---
@Biotronic created dlang/phobos pull request #7637 "Fix issue 21253 - Can't compile Variant.visit!(...) with generic func…" fixing this issue: - Fix issue 21253 - Can't compile Variant.visit!(...) with generic function https://github.com/dlang/phobos/pull/7637
dlang/phobos pull request #7637 "Fix issue 21253 - Can't compile Variant.visit!(...) with generic func…" was merged into master: - f3b20bfbf69466c20339c88bd17125cc2ed652d2 by Simen Kjærås: Fix issue 21253 - Can't compile Variant.visit!(...) with generic function https://github.com/dlang/phobos/pull/7637