Thread overview
[Issue 21697] Absurd limitations when passing lambda as alias parameter and bad error message
Mar 10, 2021
John Colvin
Mar 10, 2021
Paul Backus
Dec 17, 2022
Iain Buclaw
March 10, 2021
https://issues.dlang.org/show_bug.cgi?id=21697

John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |john.loughran.colvin@gmail.
                   |                            |com

--- Comment #1 from John Colvin <john.loughran.colvin@gmail.com> ---
The problem is triggered by the lambda being a template, yes

I expanded this to cover a bunch of cases to make sure I understood what was happening, maybe it will be useful to someone trying to solve it and/or as a comprehensive test.

module test;
import std.stdio;

//@safe:

struct S {
  //@safe:
  void foo() { writeln(&this); }
  void foo2()() { writeln(&this); }
  void runInsideDirect(alias f)() {
    write("runInsideDirect!" ~ __traits(identifier, f) ~ ": ");
    f();
  }
  void runInsideIndirect(alias f)() {
    write("runInsideIndirect!" ~ __traits(identifier, f) ~ ": ");
    auto b = &f;
    b();
  }
  void runInsideTemplateDirect(alias f)() {
    write("runInsideTemplateDirect!" ~ __traits(identifier, f) ~ ": ");
    f!()();
  }
  void runInsideTemplateIndirect(alias f)() {
    write("runInsideTemplateIndirect!" ~ __traits(identifier, f) ~ ": ");
    auto b = &f!();
    b();
  }
  void bar() {
    runInsideDirect!foo();
    runInsideIndirect!foo();
    //runOutsideDirect!foo(); // Error: need this
    runOutsideIndirect!foo(); // wrong this, caught by @safe
    runInsideTemplateDirect!foo2();
    runInsideTemplateIndirect!foo2();
    //runOutsideTemplateDirect!foo2(); // Error: need this
    runOutsideTemplateIndirect!foo2(); // wrong this, caught by @safe

    runInsideDirect!(foo2!())();
    runInsideIndirect!(foo2!())();
    //runOutsideDirect!(foo2!())(); // Error: need this
    runOutsideIndirect!(foo2!())(); // wrong this, caught by @safe

    void bar() //@safe
    {
      foo();
    }
    void bar2()() //@safe
    {
      foo();
    }
    runInsideDirect!bar();
    runInsideIndirect!bar();
    runOutsideDirect!bar();
    runOutsideIndirect!bar();
    //runInsideTemplateDirect!bar2(); // Error: need this, but no "Error
instantiating" message??
    //runInsideTemplateIndirect!bar2(); // Error: need this, but no "Error
instantiating" message??
    //runOutsideTemplateDirect!bar2(); // Error: need this
    //runOutsideTemplateIndirect!bar2(); // Error: need this

    runInsideDirect!(bar2!())();
    runInsideIndirect!(bar2!())();
    runOutsideDirect!(bar2!())();
    runOutsideIndirect!(bar2!())();
  }
}

void runOutsideDirect(alias f)() {
  write("runOutsideDirect!" ~ __traits(identifier, f) ~ ": ");
  f();
}
void runOutsideIndirect(alias f)() {
  write("runOutsideIndirect!" ~ __traits(identifier, f) ~ ": ");
  auto b = &f;
  b();
}
void runOutsideTemplateDirect(alias f)() {
  write("runOutsideTemplateDirect!" ~ __traits(identifier, f) ~ ": ");
  f!()();
}
void runOutsideTemplateIndirect(alias f)() {
  write("runOutsideTemplateIndirect!" ~ __traits(identifier, f) ~ ": ");
  auto b = &f!();
  b();
}

void main() {
  S s;
  s.bar();
}

--
March 10, 2021
https://issues.dlang.org/show_bug.cgi?id=21697

Paul Backus <snarwin+bugzilla@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |snarwin+bugzilla@gmail.com

--- Comment #2 from Paul Backus <snarwin+bugzilla@gmail.com> ---
Probably related to issue 21287, although in that case it's the lambda that works and the nested function that fails.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=21697

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P2

--
March 19
https://issues.dlang.org/show_bug.cgi?id=21697

anonymous4 <dfj1esp02@sneakemail.com> changed:

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

--- Comment #3 from anonymous4 <dfj1esp02@sneakemail.com> ---


*** This issue has been marked as a duplicate of issue 20922 ***

--