www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23062] New: Function/delegate inference example does not

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 puremagic.com
          Reporter: snarwin+bugzilla 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

--
Apr 26 2022