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: [email protected]
Reporter: [email protected]
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{ }
---
--