[Issue 23062] New: Function/delegate inference example does not compile

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 26 15:15:44 UTC 2022


https://issues.dlang.org/show_bug.cgi?id=23062

          Issue ID: 23062
           Summary: Function/delegate inference example does not compile
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dlang.org
          Assignee: nobody at puremagic.com
          Reporter: snarwin+bugzilla at gmail.com

In the spec's section on function literals [1], the example demonstrating
inference of the `function` and `delegate` keywords does not compile, due to
multiple parsing errors.

---
int abc(int delegate(int i));
int def(int function(int s));

void test()
{
    int b = 3;

    abc( int(int c) { return 6 + b; } );  // inferred to delegate
    def( uint(uint c) { return c * 2; } ); // inferred to function
  //def( int(int c) { return c * b; } );  // error!
    // Because the FunctionLiteralBody accesses b, then the function literal
type
    // is inferred to delegate. But def cannot accept a delegate argument.
}
---

[1]: https://dlang.org/spec/expression.html#function_literals

--


More information about the Digitalmars-d-bugs mailing list