Bug 8243 – cannot initialize tuple with an element at module scope but this is allowed in function-local scopes

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-06-14T11:49:10Z
Last change time
2024-12-13T18:00:32Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
timon.gehr
Moved to GitHub: dmd#18451 →

Comments

Comment #0 by timon.gehr — 2012-06-14T11:49:10Z
template TypeTuple(T...){ alias T TypeTuple; } TypeTuple!(int,int) a = 12;
Comment #1 by timon.gehr — 2012-06-14T11:49:46Z
(with DMD 2.059, the code fails to compile, but it is valid.)
Comment #2 by hsteoh — 2014-07-17T18:54:48Z
Why should this code be accepted? TypeTuple!(int,int) expects two initializers, but only one is specified.
Comment #3 by timon.gehr — 2014-07-18T08:52:22Z
(In reply to hsteoh from comment #2) > Why should this code be accepted? TypeTuple!(int,int) expects two > initializers, but only one is specified. The validity of this code should be consistent with the validity of the code below: alias Seq(T...)=T; void main(){ Seq!(int,int) a=12; } We can also just disallow that code as well, those type tuple initializers behave in a quite strange way anyway: alias Seq(T...)=T void main(){ int x=0; Seq!(int,int) a=x++; import std.stdio; writeln(a); // "01" }
Comment #4 by bearophile_hugs — 2014-07-18T08:59:37Z
(In reply to timon.gehr from comment #3) > alias Seq(T...)=T; > void main(){ > Seq!(int,int) a=12; > } I suggest to disallow this.
Comment #5 by hsteoh — 2014-07-18T14:05:38Z
I think those look like bugs. While investigating a related issue recently, I noted that some parts of dmd don't appear to treat tuple types properly, so I wouldn't be surprised if things like what you posted are unintentional bugs. To me, it makes no sense to declare something with a tuple type of multiple items, yet the initializer receives only one argument. Even if this is intentionally allowed, I'd argue it's a misfeature because it makes it too easy for a typo to silently cause bugs.
Comment #6 by timon.gehr — 2014-07-18T17:07:33Z
(In reply to hsteoh from comment #5) > I think those look like bugs. While investigating a related issue recently, > I noted that some parts of dmd don't appear to treat tuple types properly, > so I wouldn't be surprised if things like what you posted are unintentional > bugs. To me, it makes no sense to declare something with a tuple type of > multiple items, yet the initializer receives only one argument. This is allowed too: void main(){ int[2] x=2; } > Even if this is intentionally allowed, I'd assume so, though /maybe/ the duplication of side-effects is unintentional. > I'd argue it's a misfeature because it makes it > too easy for a typo to silently cause bugs. I don't disagree at all, but the behaviour should in any case be consistent.
Comment #7 by robert.schadek — 2024-12-13T18:00:32Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18451 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB