Jump to page: 1 2
Thread overview
[Issue 5290] New: Static array literals with too few elements
Nov 29, 2010
David Simcha
Sep 09, 2011
Kenji Hara
Sep 09, 2011
Kenji Hara
Sep 09, 2011
Kenji Hara
Jan 20, 2012
Walter Bright
Jan 20, 2012
timon.gehr@gmx.ch
Jan 24, 2012
Don
November 29, 2010
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: -------
September 09, 2011
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: -------
September 09, 2011
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: -------
September 09, 2011
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: -------
September 09, 2011
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: -------
September 09, 2011
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: -------
September 09, 2011
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: -------
September 09, 2011
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: -------
September 09, 2011
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: -------
January 20, 2012
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: -------
« First   ‹ Prev
1 2