Discussion Thread: DIP 1044--Enum Type Inference--Community Review Round 1

Quirin Schroll qs.il.paperinik at gmail.com
Wed Nov 30 09:25:10 UTC 2022


On Monday, 28 November 2022 at 09:33:56 UTC, XavierAP wrote:
> I didn't mean to be dismissive. And for the record I'd be OK 
> with adding to D most kinds of inference as long as it didn't 
> require new syntax (such as `$` or adding to `.`) and were 100% 
> sure and safe. This might be possible for enums at least in 
> initializations or even assignments (?) but it's not the 
> current DIP (and there are probably other difficulties even 
> with this).

There isn’t much that’s 100% safe in a pragmatic context. 
Inference for `switch`, initialization and assignment is possible 
except special compound assignments like those that lower to 
`opIndexAssign`, where the left-hand side operand need not have a 
type at all. Even then, a best-effort strategy might still be 
useful and work in almost all cases.

In many cases, an assignment `lhs = rhs` could be lowered to
```d
lhs = (){ with (typeof(lhs)) return rhs; }();
```
This might not be foolproof, but it’s probably “safe unless you 
do obvious stupid”.


More information about the Digitalmars-d mailing list