Thread overview
[Issue 8243] cannot initialize tuple with an element at module scope but this is allowed in function-local scopes
[Issue 8243] cannot initialize tuple with an element at module scope
Jul 18, 2014
timon.gehr@gmx.ch
Jul 18, 2014
timon.gehr@gmx.ch
Dec 17, 2022
Iain Buclaw
July 17, 2014
https://issues.dlang.org/show_bug.cgi?id=8243

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx

--- Comment #2 from hsteoh@quickfur.ath.cx ---
Why should this code be accepted? TypeTuple!(int,int) expects two initializers, but only one is specified.

--
July 18, 2014
https://issues.dlang.org/show_bug.cgi?id=8243

--- Comment #3 from timon.gehr@gmx.ch ---
(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"
}

--
July 18, 2014
https://issues.dlang.org/show_bug.cgi?id=8243

bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc

--- Comment #4 from bearophile_hugs@eml.cc ---
(In reply to timon.gehr from comment #3)

> alias Seq(T...)=T;
> void main(){
>     Seq!(int,int) a=12;
> }

I suggest to disallow this.

--
July 18, 2014
https://issues.dlang.org/show_bug.cgi?id=8243

--- Comment #5 from hsteoh@quickfur.ath.cx ---
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.

--
July 18, 2014
https://issues.dlang.org/show_bug.cgi?id=8243

timon.gehr@gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|cannot initialize tuple     |cannot initialize tuple
                   |with an element at module   |with an element at module
                   |scope                       |scope but this is allowed
                   |                            |in function-local scopes

--- Comment #6 from timon.gehr@gmx.ch ---
(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.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=8243

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P3

--