RFC: Last words on Primary Type Syntax aka. `ref` return function pointer type sytnax
Quirin Schroll
qs.il.paperinik at gmail.com
Fri Jul 4 13:51:16 UTC 2025
On Friday, 4 July 2025 at 12:27:51 UTC, IchorDev wrote:
> On Thursday, 3 July 2025 at 17:31:17 UTC, Quirin Schroll wrote:
>> A more relevant example would be an array or slice of function
>> pointers. There’s a stylistic urge to write `(void
>> function())[]` instead of `void function()[]`, but the
>> proposed parsing rule locks one in: With `scope`, it’s `scope
>> void function()[]` without `ref` and `scope (ref void
>> function())[]` or `scope (ref void function()[])`, but not
>> `scope ((ref void function())[])` with `ref`. The last one is
>> excluded because, given the inner parentheses, the outer ones
>> aren’t required anymore.
>
> Walter, no! Don’t do this to the beautiful primary type syntax!
> My head hurts reading this mess of confusion! Why is adding
> superfluous parenthesis disallowed?? Why don’t we add this
> behaviour binary expressions too?!
> ```d
> auto a = (1 * 2) + 3; //ERROR: 1 * 2 would already be performed
> first and therefore must not be parenthesised
> ```
> There is nothing wrong with the proposed syntax except that it
> is a bandaid solution to a larger syntactical blunder: `ref`
> needs to be able to mean multiple things within the same context
Just for reference, “If what follows one of the four keywords
inside parentheses” is a very specific context. He’s not
proposing to do this generally.
```d
// Walter’s proposal
static int x;
(int function())[2] fps1 = [() => x, () => ++x]; // okay
scope (int function())[2] fps2 = [() => x, () => ++x]; //
error
scope (ref int function())[2] fps3 = [() => x, () => ++x]; // okay
```
Rationale:
* The first one is okay because there’s nothing in front of it
that takes optional arguments.
* The second one is an error because `scope` takes optional
arguments and `int function()` (that what’s in parentheses)
doesn’t require these parentheses.
* The third one is okay because, despite `scope` taking optional
arguments, the type `ref int function()` requires parentheses.
More information about the Digitalmars-d
mailing list