Bug 21253 – Can't compile Variant.visit!(...) with generic function
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-09-16T03:47:26Z
Last change time
2020-10-31T01:54:00Z
Keywords
pull
Assigned to
No Owner
Creator
qqq
Comments
Comment #0 by fitare2749 — 2020-09-16T03:47:26Z
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{ }
---
Comment #1 by dlang-bot — 2020-09-17T07:29:20Z
@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
Comment #2 by dlang-bot — 2020-10-31T01:54:00Z
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