Bug 7015 – Allow vector operations into newly declared array

Status
NEW
Severity
enhancement
Priority
P4
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-11-25T17:05:12Z
Last change time
2024-12-07T13:31:36Z
Keywords
diagnostic, spec
Assigned to
No Owner
Creator
bearophile_hugs
Moved to GitHub: dmd#17115 →

Comments

Comment #0 by bearophile_hugs — 2011-11-25T17:05:12Z
While writing some D code that uses vectors and the desire to find distances among them, I'd like this vector operation to be supported: void main() { int[] a = [1, 2, 3]; int[] b = a[] ^^ 2; } DMD 2.057head gives: test.d(3): Error: Array operation a[] ^^ 2 not implemented
Comment #1 by smjg — 2011-12-10T08:58:48Z
How, exactly, does this differ from (marked fixed) issue 3661?
Comment #2 by bearophile_hugs — 2011-12-10T10:36:52Z
(In reply to comment #1) > How, exactly, does this differ from (marked fixed) issue 3661? Thank you Stewart, you are right. Vector pow is already implemented: import std.math, std.stdio; void main() { int[3] a = [1, 2, 3]; int[3] b; b = a[] ^^ 2; writeln(b); a[] ^^= 2; writeln(a, " ", b); } So this is a: 1) A diagnostic bug, because the error message is misleading. 2) It shows a more general design problem with vector operations, because code like this too is refused with a similar error message: void main() { int[] a = [1, 2, 3]; int[] b = a[] + 2; } Vector ops require the memory needed to store the result to be already present. I don't know if this will change. What do you suggest to do with this bug report, to close it?
Comment #3 by smjg — 2011-12-10T17:18:34Z
So the language currently doesn't allow vector ops into a newly declared array. So this is really two things: (a) as you say, a diagnostic bug, as the error message when you try to do it is bogus (b) a language feature request to allow this code I'm guessing (a) and (b) need to be filed as two separate issues. But meanwhile, I'm changing the summary line so that it at least makes sense.
Comment #4 by r.97all — 2015-08-27T21:33:56Z
(In reply to Stewart Gordon from comment #3) > So this is really two things: > (a) as you say, a diagnostic bug, as the error message when you try to do it > is bogus > (b) a language feature request to allow this code Maybe (b) is a duplicate of 2548
Comment #5 by robert.schadek — 2024-12-07T13:31:36Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17115 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB