www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5290] New: Static array literals with too few elements

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290

           Summary: Static array literals with too few elements
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: accepts-invalid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dsimcha yahoo.com


--- Comment #0 from David Simcha <dsimcha yahoo.com> 2010-11-29 05:55:24 PST ---
The following invalid code is accepted:

import std.stdio;

void main() {
    real[2] foo = [1.0L];
    writeln(foo);  // [1, 0]
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 29 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #1 from Kenji Hara <k.hara.pg gmail.com> 2011-09-09 09:35:47 PDT ---
https://github.com/D-Programming-Language/dmd/pull/375

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290


bearophile_hugs eml.cc changed:

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


--- Comment #2 from bearophile_hugs eml.cc 2011-09-09 10:29:30 PDT ---
(In reply to comment #1)
 https://github.com/D-Programming-Language/dmd/pull/375
Pull 375 is not about bug 3849 too, right? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #3 from Kenji Hara <k.hara.pg gmail.com> 2011-09-09 10:40:55 PDT ---
Pull 375 does not support `int[$] = [1, 2, 3];`.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #4 from bearophile_hugs eml.cc 2011-09-09 11:00:10 PDT ---
(In reply to comment #3)
 Pull 375 does not support `int[$] = [1, 2, 3];`.
OK. This is expected. Currenly DMD runs code like this (I don't like this, but this is working as designed!): int[3] arr = [1, 2]; void main() {} I presume Pull 375 lets this kind of code pass, right? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2011-09-09 11:23:57 PDT ---
(In reply to comment #4)
 int[3] arr = [1, 2];
 void main() {}

 I presume Pull 375 lets this kind of code pass, right?
??? Pull 375 rejects statically above code, it is expected behavior from this issue. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #6 from bearophile_hugs eml.cc 2011-09-09 11:31:56 PDT ---
(In reply to comment #5)

 ??? Pull 375 rejects statically above code, it is expected behavior from this
 issue.
I see. I suggest you to read the whole thread of bug 3849. Code like the following is working as designed, so if your patch refuses this code, then your patch is implementing an enhancement too (it means it's changing the D specs): int[3] arr = [1, 2]; void main() {} Note that I support turning this kind of code into a compile-time error, but Walter (used to) wants it to compile. So at least I suggest your comment of Pull 375 to say this example is now a compile-time error. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #7 from bearophile_hugs eml.cc 2011-09-09 11:34:38 PDT ---
(In reply to comment #6)

 Code like the following is working as designed, so if your patch refuses this
 code, then your patch is implementing an enhancement too (it means it's
 changing the D specs):
 
 int[3] arr = [1, 2];
 void main() {}
Note: For the situations where people want to specify less items than the arrays length I suggested an *explicit* syntax, like: int[3] arr = [1, 2, ...]; void main() {} -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Sep 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #8 from bearophile_hugs eml.cc 2011-09-09 11:52:16 PDT ---
See also:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=144210

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 09 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #9 from Walter Bright <bugzilla digitalmars.com> 2012-01-20
12:57:27 PST ---
(In reply to comment #0)
 The following invalid code is accepted:
 import std.stdio;
 void main() {
     real[2] foo = [1.0L];
     writeln(foo);  // [1, 0]
 }
Running it gives: object.Exception src\rt\arraycat.d(31): lengths don't match for array copy -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #10 from bearophile_hugs eml.cc 2012-01-20 15:08:36 PST ---
(In reply to comment #9)
 (In reply to comment #0)
 The following invalid code is accepted:
 import std.stdio;
 void main() {
     real[2] foo = [1.0L];
     writeln(foo);  // [1, 0]
 }
Running it gives: object.Exception src\rt\arraycat.d(31): lengths don't match for array copy
D is statically typed, so it's better to refuse it at compile-time. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr gmx.ch


--- Comment #11 from timon.gehr gmx.ch 2012-01-20 15:38:41 PST ---
Actually, it would be very cool if D would re-use the integer range trick here
and catch all cases that can be proven not to work using it, such that the
following code would error at compile time: ;)

int x;
readf("%d",&x);
real[2] foo = 
    x%100>50 ?
    [1.0L, 2.0L, 3.0L][0..2|x&1] :
    ([1.0L, 2.0L] ~ [3.0L, 4.0L] ~ 5.0L)[x&1..$-!(x&1)];

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 20 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5290


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au


--- Comment #12 from Don <clugdbug yahoo.com.au> 2012-01-24 06:29:05 PST ---
(In reply to comment #10)
 (In reply to comment #9)
 (In reply to comment #0)
 The following invalid code is accepted:
 import std.stdio;
 void main() {
     real[2] foo = [1.0L];
     writeln(foo);  // [1, 0]
 }
Running it gives: object.Exception src\rt\arraycat.d(31): lengths don't match for array copy
D is statically typed, so it's better to refuse it at compile-time.
Yes, but that's bug 2547. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 24 2012