Thread overview
[Issue 20388] Parse error when compiling lambdas in mixins as template parameters
Nov 15, 2019
RazvanN
Nov 17, 2019
Basile-z
Nov 17, 2019
RazvanN
Nov 18, 2019
Boris Carvajal
Nov 18, 2019
Dlang Bot
Nov 18, 2019
Dlang Bot
Mar 21, 2020
Basile-z
November 15, 2019
https://issues.dlang.org/show_bug.cgi?id=20388

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
I have not checked, but it may be possible that this PR: https://github.com/dlang/dmd/pull/10215 introduced the regression

--
November 17, 2019
https://issues.dlang.org/show_bug.cgi?id=20388

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |b2.temp@gmx.com

--- Comment #2 from Basile-z <b2.temp@gmx.com> ---
That is indeed the PR you menton that caused the regression. The problem is that it's hard to fix. There's a lookup that considers that the construct

   'mixin' '('(<anything here with balanced L/R paren>)* ')'

(https://github.com/dlang/dmd/pull/10215/files#diff-cd066d37445cac534313c0137c2d4bbeR6935)

is always a type. In the present case the "(<anything here with balanced L/R paren>)* is a string literal. To fix the bug the string literal should be scanned to determine if it represents the source code for a type or not.

But even with that we can easily imagine similar cases where the string literal is made of several symbols representing strings and that require CTFE to build the final string to mix. Add to this the problem of out of order declarations. Example:

---
void main() {
    int a;
    foo!(mixin(RetType, Body))();
}

enum RetType = "()";
enum Body = "{}";

void foo(alias t)() {
}
---

In other word I think this bug CANNOT be fixed at all.

--
November 17, 2019
https://issues.dlang.org/show_bug.cgi?id=20388

--- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> ---
A partial solution that may solve other cases would be to treat string mixins at parse time. Once the parser determines that the mixin is a string it can ignore the mixin part and simply paste the string.

--
November 18, 2019
https://issues.dlang.org/show_bug.cgi?id=20388

Boris Carvajal <boris2.9@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |boris2.9@gmail.com

--- Comment #4 from Boris Carvajal <boris2.9@gmail.com> ---
Something as simple as this fails now:

foo!(mixin("1+1"))();

In this context the old behavior of parsing mixin as an expression should be restored (it worked from 2.063 according to run.dlang.io).

Another bug needs to be open to allow the new "mixin type" here, if it's ever possible.

--
November 18, 2019
https://issues.dlang.org/show_bug.cgi?id=20388

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@BorisCarvajal created dlang/dmd pull request #10584 "Fix issue 20388 - Parse mixin as an expression in template parameters" fixing this issue:

- Fix issue 20388 - Parse mixin as an expression in template parameters

https://github.com/dlang/dmd/pull/10584

--
November 18, 2019
https://issues.dlang.org/show_bug.cgi?id=20388

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #10584 "Fix issue 20388 - Parse mixin as an expression in template parameters" was merged into stable:

- 764e10c0dd64f0c4729e08c58acddd430d79946a by Boris Carvajal:
  Fix issue 20388 - Parse mixin as an expression in template parameters

https://github.com/dlang/dmd/pull/10584

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=20388

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--