[Issue 2753] Cannot declare pointer to function returning ref
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Oct 25 13:59:07 UTC 2022
    
    
  
https://issues.dlang.org/show_bug.cgi?id=2753
Bolpat <qs.il.paperinik at gmail.com> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |qs.il.paperinik at gmail.com
--- Comment #10 from Bolpat <qs.il.paperinik at gmail.com> ---
@Walter: It is “broken” in the sense that the grammar should(!) be able to
express a type without requiring type aliases.
I’d suggest minimal changes to the Type grammar to allow for it. 
TL;DR: The semantics is obvious, I hope. Let’s allow the following:
```d
ref (int function()) f1();
(ref int function()) f2();
void g1(ref (int function()) fp);
void g2((ref int function()) fp);
void hImpl(DG : ref int delegate())(DG dg) { }
alias h = fImpl!(ref int delegate() @safe);
```
――― End of TL;DR ―――
Note that `f1` and `g1` are equivalent to:
```d
ref int function() f1();
void g1(ref int function() fp);
```
In the grammar, I use `?` to signify optional occurrence.
```diff
  Type:
      TypeCtors? BasicType TypeSuffixes?
+     ref TypeCtors? BasicType CallableSuffix TypeSuffixes?
    BasicType:
        FundamentalType
        . QualifiedIdentifier
        QualifiedIdentifier
        Typeof
        Typeof . QualifiedIdentifier
−       TypeCtor ( Type )
+       TypeCtor? ( Type )
        Vector
        TraitsExpression
        MixinType
    TypeSuffix:
        *
        [ ]
        [ AssignExpression ]
        [ AssignExpression .. AssignExpression ]
        [ Type ]
+       CallableSuffix
+   
+   CallableSuffix:
        delegate Parameters MemberFunctionAttributes?
        function Parameters FunctionAttributes?
```
(This grammar diff does not address the special casing for `alias` that is
currently in place and superseded by this. As far as I can tell, it’ll be still
good and should not be changed.)
It is worth considering to deprecate the syntax without disambiguating
parentheses, akin to comparison and bit-wise operators and `() => { }`. The
deprecation only applies to cases where a non-aliased function pointer or
delegate type is used on a `ref` parameter or as the return type of a `ref`
returning function.
--
    
    
More information about the Digitalmars-d-bugs
mailing list