Thread overview
What is "dual-context" ?
2 days ago
SrMordred
2 days ago
Paul Backus
1 day ago
SrMordred
2 days ago
source\app.d(37,10): Error: function `app.main.match!((some) => print(some), (none) => print("none")).match` requires a dual-context, which is not yet supported by LDC

I was playing with my home made "sumtypes".
The code below works fine in dmd, but in ldc it triggers that error.

x.match!(some => print(some), none => print("none"));


What exactly is this "dual-context"?


2 days ago
On Friday, 13 September 2019 at 02:49:33 UTC, SrMordred wrote:
> source\app.d(37,10): Error: function `app.main.match!((some) => print(some), (none) => print("none")).match` requires a dual-context, which is not yet supported by LDC
>
> I was playing with my home made "sumtypes".
> The code below works fine in dmd, but in ldc it triggers that error.
>
> x.match!(some => print(some), none => print("none"));
>
>
> What exactly is this "dual-context"?

"Dual context" is the compiler feature that allows you to pass delegates as template arguments to member functions. For a long time, limitations in the frontend made this impossible [1]. It was recently fixed in dmd [2], but the fix hasn't made it into ldc yet [3], so code that takes advantage of this feature is currently dmd-only.

The easiest way to work around the issue is to make `match` a non-member function, and call it using UFCS. This is what the dub package `sumtype` does [4].

[1] https://issues.dlang.org/show_bug.cgi?id=5710
[2] https://github.com/dlang/dmd/pull/9282
[3] https://github.com/ldc-developers/ldc/issues/3125
[4] https://github.com/pbackus/sumtype/blob/v0.8.13/src/sumtype.d#L1091-L1106
1 day ago
On Friday, 13 September 2019 at 04:23:47 UTC, Paul Backus wrote:
> On Friday, 13 September 2019 at 02:49:33 UTC, SrMordred wrote:
>> [...]
>
> "Dual context" is the compiler feature that allows you to pass delegates as template arguments to member functions. For a long time, limitations in the frontend made this impossible [1]. It was recently fixed in dmd [2], but the fix hasn't made it into ldc yet [3], so code that takes advantage of this feature is currently dmd-only.
>
> [...]

Nice!, Thanks for the explanation and workaround :)