[Issue 5290] Static array literals with too few elements

2022-03-09 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=5290

Mathias LANG  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||pro.mathias.l...@gmail.com
 Resolution|--- |WORKSFORME

--- Comment #13 from Mathias LANG  ---
As of 2.099, the OP sample properly errors out.

There's still a few issues related to this. For example, issue 19095 still
applies, but a PR for it was made and closed due to the effect it had on code.
But closing this as "WORKSFORME" since the other issues are more fine-grained,
up-to-date, and have discussions.

--


[Issue 5290] Static array literals with too few elements

2016-04-27 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=5290

Nick Treleaven  changed:

   What|Removed |Added

 CC||ntrel-...@mybtinternet.com
   See Also||https://issues.dlang.org/sh
   ||ow_bug.cgi?id=3849

--


[Issue 5290] Static array literals with too few elements

2012-01-24 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290


Don  changed:

   What|Removed |Added

 CC||clugd...@yahoo.com.au


--- Comment #12 from Don  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: ---


[Issue 5290] Static array literals with too few elements

2012-01-20 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290


timon.g...@gmx.ch changed:

   What|Removed |Added

 CC||timon.g...@gmx.ch


--- Comment #11 from timon.g...@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: ---


[Issue 5290] Static array literals with too few elements

2012-01-20 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #10 from bearophile_h...@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: ---


[Issue 5290] Static array literals with too few elements

2012-01-20 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290


Walter Bright  changed:

   What|Removed |Added

 CC||bugzi...@digitalmars.com


--- Comment #9 from Walter Bright  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: ---


[Issue 5290] Static array literals with too few elements

2011-09-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #8 from bearophile_h...@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: ---


[Issue 5290] Static array literals with too few elements

2011-09-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #7 from bearophile_h...@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: ---


[Issue 5290] Static array literals with too few elements

2011-09-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #6 from bearophile_h...@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: ---


[Issue 5290] Static array literals with too few elements

2011-09-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #5 from Kenji Hara  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: ---


[Issue 5290] Static array literals with too few elements

2011-09-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #4 from bearophile_h...@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: ---


[Issue 5290] Static array literals with too few elements

2011-09-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290



--- Comment #3 from Kenji Hara  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: ---


[Issue 5290] Static array literals with too few elements

2011-09-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290


bearophile_h...@eml.cc changed:

   What|Removed |Added

 CC||bearophile_h...@eml.cc


--- Comment #2 from bearophile_h...@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: ---


[Issue 5290] Static array literals with too few elements

2011-09-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=5290


Kenji Hara  changed:

   What|Removed |Added

   Keywords||patch


--- Comment #1 from Kenji Hara  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: ---