digitalmars.D.bugs - [Issue 21253] New: Can't compile Variant.visit!(...) with generic
- d-bugmail puremagic.com (39/43) Sep 15 2020 https://issues.dlang.org/show_bug.cgi?id=21253
https://issues.dlang.org/show_bug.cgi?id=21253 Issue ID: 21253 Summary: Can't compile Variant.visit!(...) with generic function Product: D Version: D2 Hardware: x86_64 OS: Windows Status: NEW Severity: normal Priority: P1 Component: phobos Assignee: nobody puremagic.com Reporter: fitare2749 araniera.net 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 --versionDMD32 D Compiler v2.091.0-beta.2-master-ec39fe5dmd code.d -vcolumnscode.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.dimport std; void main() { Algebraic!(A, B)().visit!( (B _) => 42, (a ) => a.n ); } struct A{int n;} struct B{ } --- --
Sep 15 2020