named arguments, string interpolation, please stop.

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Thu Jan 11 23:43:24 UTC 2024


On 12/01/2024 12:29 PM, Timon Gehr wrote:
>     What I'm wondering now is if we can reframe the problem, so that
>     contract invalidation is an application of the template solution, so
>     that it can scale without further hacks.
> 
> Well, you can view
> 
> |int opApply(@called scope int delegate() dg)b{ ... } |
> 
> As syntactic sugar for:
> 
> |int opApply[functionAttribute __a37 :> b](scope int delegate()__a37 
> dg)__a37{ ... } |
> 
> Where |a :> b| means you can call a |b| function from an |a| context, 
> i.e., |__a37| may weaken the guarantees given by |b| and allow function 
> types that can type more values into the function.

Yes.

We'd still need to keep the ``scope`` stuff on the delegate wrt. 
``@safe`` as part of the weakening logic.

However I think the main thing is that the function body gets typed 
checked with the assumption that the most restrictive set holds. And 
only the caller sees that the contract has been invalidated in the error 
case.

Now we really only need to come up with a story that can be easily 
described to the user in both simple and complex cases, and describe it 
to the compiler also.



More information about the Digitalmars-d mailing list