Make -preview=intpromote not suck

Dukc ajieskola at gmail.com
Tue Oct 27 23:13:01 UTC 2020


On Monday, 26 October 2020 at 13:06:09 UTC, Steven Schveighoffer 
wrote:
> [snip]
>
> -Steve

Wouldn't it be simpler if integer promoting expressions were 
implicitly castable to types they were promoted from, meaning:

```
short a = 1, b = 2;
short c = a+b; //fine, int promoted from short implicitly 
castable back
auto i = a+b; //int, because the type is still int if not casted
short d = cast(short)i; //cast required here, promotion 
reversibility applies only for expressions
byte e = cast(byte)(a+b); //cast required because byte is smaller 
than short
```

Won't solve both your problem and a whole host of others with 
`byte`s and `short`s?

It should not be too hard to implement either, as array literals 
already do the same. They are implicitly castable to static 
arrays of their own size, while their type (dynamic array) is not.


More information about the Digitalmars-d mailing list