digitalmars.D.learn - What is "dual-context" ?
- SrMordred (8/8) Sep 12 2019 source\app.d(37,10): Error: function `app.main.match!((some) =>
 - Paul Backus (15/23) Sep 12 2019 "Dual context" is the compiler feature that allows you to pass
 - SrMordred (2/11) Sep 13 2019 Nice!, Thanks for the explanation and workaround :)
 
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"?
 Sep 12 2019
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
 Sep 12 2019
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:Nice!, Thanks for the explanation and workaround :)[...]"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. [...]
 Sep 13 2019








 
 
 
 SrMordred <patric.dexheimer gmail.com>