Re: templated overload of opAssign

2021-04-05 Thread Paul Backus via Digitalmars-d-learn
On Saturday, 3 April 2021 at 13:46:17 UTC, kdevel wrote: Why does this code [...] ```d ec.opAssign (bar (1)); // okay // ec = bar (1); // Error: expression bar(1) is void and has no value ``` [...] compile with the abovementioned error? This is a compiler bug. You're not allowed to hav

Re: templated overload of opAssign

2021-04-05 Thread kdevel via Digitalmars-d-learn
On Monday, 5 April 2021 at 20:59:34 UTC, tsbockman wrote: However, `=` and `~=` should not treat `lazy void` parameters differently. They should either both work, or neither. I checked and this is actually a very old regression; both worked way back in DMD 2.061. So, I've filed a front-end bug

Re: templated overload of opAssign

2021-04-05 Thread tsbockman via Digitalmars-d-learn
On Monday, 5 April 2021 at 05:22:22 UTC, frame wrote: On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote: Thus, the solution is to use an explicit `delegate` instead of `lazy`: Yes, I forgot to mention that. Could you please explain why you set 'scope' here? Isn't it wanted to keep

Re: templated overload of opAssign

2021-04-05 Thread tsbockman via Digitalmars-d-learn
On Monday, 5 April 2021 at 15:05:24 UTC, kdevel wrote: You changed the definition of ``bar`` while the exception collector (``EC``) is meant to catch and collect an exception thrown from the *unmodified* function. My point was that the code will work if you do explicitly what `lazy` does impl

Re: templated overload of opAssign

2021-04-05 Thread Imperatorn via Digitalmars-d-learn
On Monday, 5 April 2021 at 15:05:24 UTC, kdevel wrote: On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote: ``` [...] [...] [...] [...] ``` [...] Nice, is this documented somewhere? 🤔 Maybe we could add a better error message or smth.

Re: templated overload of opAssign

2021-04-05 Thread kdevel via Digitalmars-d-learn
On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote: ``` [...] You cannot assign void returned from bar() as parameter to opAssign(). The lazy keyword creates some internal delegate, thus opAssign() works instead. [...] auto bar (int i) { return () { if (i == 1) th

Re: templated overload of opAssign

2021-04-04 Thread frame via Digitalmars-d-learn
On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote: Thus, the solution is to use an explicit `delegate` instead of `lazy`: Yes, I forgot to mention that. Could you please explain why you set 'scope' here? Isn't it wanted to keep references here?

Re: templated overload of opAssign

2021-04-04 Thread tsbockman via Digitalmars-d-learn
On Sunday, 4 April 2021 at 16:38:10 UTC, frame wrote: On Saturday, 3 April 2021 at 13:46:17 UTC, kdevel wrote: Why does this code ec.opAssign (bar (1)); // okay // ec = bar (1); // Error: expression bar(1) is void and has no value compile with the abovementioned error? You cannot a

Re: templated overload of opAssign

2021-04-04 Thread frame via Digitalmars-d-learn
On Saturday, 3 April 2021 at 13:46:17 UTC, kdevel wrote: Why does this code ec.opAssign (bar (1)); // okay // ec = bar (1); // Error: expression bar(1) is void and has no value compile with the abovementioned error? You cannot assign void returned from bar() as parameter to opAssig