D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21253 - Can't compile Variant.visit!(...) with generic function
Summary: Can't compile Variant.visit!(...) with generic function
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-09-16 03:47 UTC by qqq
Modified: 2020-10-31 01:54 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description qqq 2020-09-16 03:47:26 UTC
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 Dlang Bot 2020-09-17 07:29:20 UTC
@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 Dlang Bot 2020-10-31 01:54:00 UTC
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