Array literals are weird.

Imperatorn johan_forsberg_86 at hotmail.com
Wed May 5 09:28:45 UTC 2021


On Wednesday, 5 May 2021 at 09:18:58 UTC, Imperatorn wrote:
> On Wednesday, 5 May 2021 at 08:58:41 UTC, user1234 wrote:
>> On Saturday, 1 May 2021 at 11:32:47 UTC, Blatnik wrote:
>>> I love how D redesigned the terrible C/C++ arrays. And it's 
>>> awesome that array operations like element wise +, -, etc. 
>>> are built into the language - it makes me want to use arrays 
>>> and slices for everything. But there are still some rough 
>>> edges in the design.
>
> I have experimented some and found a few workarounds which 
> might be acceptable.
>
> But, I'm having some weird bug. On dmd and dmd-beta it works, 
> but on dmd-nightly I get:
>
> cannot interpret array literal expression [1, 2, 3] + [3, 2, 1] 
> at compile time
>
> I think this might be a regression?
>
> Like, this works as I want:
> https://run.dlang.io/is/rHRiP9
>
> If I use dmd or dmd-beta. But if I change it to dmd-nightly it 
> doesn't :(
>
> 😢😢😢

Output locally from https://run.dlang.io/is/ZUFFfZ:

PS C:\Temp\D\temp> dmd .\arrays.d
2096L
PS C:\Temp\D\temp> .\arrays.exe
[4, 4, 4]
[4, 4, 4]
[4, 4, 4]
[4, 4, 4]
[4, 4, 4]
PS C:\Temp\D\temp> ldc2 .\arrays.d
2096L
PS C:\Temp\D\temp> .\arrays.exe
[4, 4, 4]
[4, 4, 4]
[4, 4, 4]
[4, 4, 4]
[4, 4, 4]



More information about the Digitalmars-d mailing list