[Issue 3374] [tdpl] ICE(init.c): Associative array type not inferred

2009-10-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3374


Don clugd...@yahoo.com.au changed:

   What|Removed |Added

   Keywords||patch
   Platform|Other   |All
Version|unspecified |2.033
 OS/Version|Linux   |All


--- Comment #1 from Don clugd...@yahoo.com.au 2009-10-09 00:32:48 PDT ---
The ICE only occurs if it's inside a function. BTW if you change 'auto' into
enum, and
'assert' into 'static assert', it also works with the patch in place.
void bug3374()
{
   auto famousNamedConstants = 
[ pi : 3.14, e : 2.71, moving sofa : 2.22 ];

assert(famousNamedConstants[e]==2.71);
}

There are two parts to this patch. The first part, in
ArrayInitializer::toExpression() is just for the ICE.
The ICE occurs because it's not checking for an ERROR type. (was NULL in D1).
This changes it from
ice-on-valid-code into rejects-valid. To completely fix the bug requires the
second part.

The second part, in ArrayInitializer::inferType(Scope *sc), is for the AA type
inference.
But, I had to do a semantic on the expression. Not sure if that's OK. This part
of the patch is for D1 as well.

PATCH against DMD 2.033. init.c, ArrayInitializer::toExpression(), line 407.
Index: init.c
===
--- init.c(revision 201)
+++ init.c(working copy)
@@ -404,6 +404,7 @@
 Type *t = NULL;
 if (type)
 {
+if (type == Type::terror) goto Lno;
 t = type-toBasetype();
 switch (t-ty)
 {
@@ -542,8 +543,18 @@
 return type;

 Lno:
-error(loc, cannot infer type from this array initializer);
-return Type::terror;
+Initializer *iz = (Initializer *)value.data[0];
+Expression *indexinit = (Expression *)index.data[0];
+if (iz  indexinit)
+{   Type *t = iz-inferType(sc);
+indexinit = indexinit-semantic(sc);
+Type *indext = indexinit-type;
+t = new TypeAArray(t, indext);
+t = t-semantic(loc, sc);
+type = t;
+}
+return type;
+
 }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3381] [tdpl] Incorrect assessment of overriding in triangular-shaped hierarchy

2009-10-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3381


Gide Nwawudu g...@nwawudu.com changed:

   What|Removed |Added

   Keywords||diagnostic, rejects-valid
 CC||g...@nwawudu.com
 OS/Version|Linux   |All


--- Comment #1 from Gide Nwawudu g...@nwawudu.com 2009-10-09 02:10:50 PDT ---
Looks like at dup of bug 3023.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3382] New: Implement uniform function call syntax

2009-10-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3382

   Summary: Implement uniform function call syntax
   Product: D
   Version: unspecified
  Platform: All
OS/Version: All
Status: NEW
  Severity: enhancement
  Priority: P2
 Component: DMD
AssignedTo: nob...@puremagic.com
ReportedBy: d...@me.com


--- Comment #0 from Jacob Carlborg d...@me.com 2009-10-09 03:38:28 PDT ---
Created an attachment (id=470)
The patch partly implements this enhancement

This is a suggestion to implement the uniform function call syntax that was
talked about in the first D conference. See the newsgroup thread for more info:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.Darticle_id=97654

I've supplied a patch that partly implements this enhancement. Literals don't
work with the patch, this works with the patch: x.foo(), this doesn't work:
3.foo(). I think the parser or similar must be changed for 3.foo() to work.

I'm not sure if any of the added types in the patch should be removed or if
some other types should be added.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3119] Segfault(expression.c) template function overloads with function with same name in other module

2009-10-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3119


Don clugd...@yahoo.com.au changed:

   What|Removed |Added

   Platform|x86_64  |All
Summary|Segfault combining  |Segfault(expression.c)
   |std.c.linux and passing a   |template function overloads
   |ref string  |with function with same
   ||name in other module
 OS/Version|Linux   |All
   Severity|minor   |normal


--- Comment #2 from Don clugd...@yahoo.com.au 2009-10-09 05:23:42 PDT ---
Reduced test case. Applies on any OS (not Linux specific), but D2 only since it 
involves overload sets.
Import order is important! If order of imports is swapped, generates Error: 
expected 1 function arguments, not 0.
Segfaulting in CallExp::semantic(). e1-type is garbage. (not NULL, garbage!)


import bugB;
import bugC;

void main() {  foo(); }

 bugB.d:

void foo(int) {} 
---
bugC.d:
---
void foo(T)(){}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3378] [tdpl] ++x should be an lvalue

2009-10-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3378


Don clugd...@yahoo.com.au changed:

   What|Removed |Added

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


--- Comment #1 from Don clugd...@yahoo.com.au 2009-10-09 06:37:38 PDT ---
(In reply to comment #0)
 1. The increment is rewritten as x += 1, but it shouldn't as it's a
 fundamentally different operation

From the spec: 
Overloading ++e and --e
Since ++e is defined to be semantically equivalent to (e += 1), the expression
++e is rewritten as (e += 1), and then checking for operator overloading is
done. 

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3119] Segfault(expression.c) template function overloads with function with same name in other module

2009-10-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3119


Don clugd...@yahoo.com.au changed:

   What|Removed |Added

   Keywords||patch


--- Comment #3 from Don clugd...@yahoo.com.au 2009-10-09 07:36:36 PDT ---
ANALYSIS:
expression.c, line 6693:

if (!f)
{   /* No overload matches, just set f and rely on error
 * message being generated later.
 */
f = (FuncDeclaration *)eo-vars-a.data[0];
}

This is wrong because it's not necessarily a FuncDeclaration, it could be a
TemplateDeclaration instead. I think an error message needs to be generated
immediately.

Change this to something like:

if (!f)
{   /* No overload matches, just set f and rely on error
 * message being generated later.
 */
error(no overload matches %s, savedFuncName);
return this;
}

after having added to line 6320 something like:

istemp = 0;
Lagain:
+char *savedFuncName = toChars();
//printf(Lagain: %s\n, toChars());
f = NULL;
if (e1-op == TOKthis || e1-op == TOKsuper)
{
// semantic() run later for these
}
else
{
UnaExp::semantic(sc);

since the UnaExp::semantic() call turns the name into __overloadset which makes
yucky error messages.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3378] [tdpl] ++x should be an lvalue

2009-10-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3378



--- Comment #2 from Andrei Alexandrescu and...@metalanguage.com 2009-10-09 
09:09:03 PDT ---
(In reply to comment #1)
 (In reply to comment #0)
  1. The increment is rewritten as x += 1, but it shouldn't as it's a
  fundamentally different operation
 
 From the spec: 
 Overloading ++e and --e
 Since ++e is defined to be semantically equivalent to (e += 1), the expression
 ++e is rewritten as (e += 1), and then checking for operator overloading is
 done. 

I know, I know! That spec must be definitely changed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3383] New: newVoid

2009-10-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3383

   Summary: newVoid
   Product: D
   Version: 2.033
  Platform: Other
OS/Version: Windows
Status: NEW
  Keywords: patch, performance
  Severity: enhancement
  Priority: P2
 Component: Phobos
AssignedTo: nob...@puremagic.com
ReportedBy: dsim...@yahoo.com


--- Comment #0 from David Simcha dsim...@yahoo.com 2009-10-09 10:08:58 PDT ---
D's new keyword for allocating dynamic arrays initializes the data to T.init. 
This is a perfectly reasonable safe default.  However, there should be an
obvious way to optimize this out if one is sure one doesn't need it, as there
is for static arrays.  Below is a proposed function, newVoid(), that should go
in std.array to allow such a thing.

import core.memory;

/**Gives the block attribute that a block containing type T should have,
 * i.e. scan or NO_SCAN.*/
GC.BlkAttr blockAttribute(T)() {
if(typeid(T).flags  1) {
return cast(GC.BlkAttr) 0;
} else {
return GC.BlkAttr.NO_SCAN;
}
}

unittest {
assert(blockAttribute!(uint)() == GC.BlkAttr.NO_SCAN);
assert(blockAttribute!(void*)() == cast(GC.BlkAttr) 0);
}

/**Returns a new array of type T w/o initializing elements.
 *
 * Examples:
 * ---
 * auto foo = newVoid!uint(5);
 * foreach(i; 0..5) {
 * foo[i] = i;
 * }
 * ---
 */
T[] newVoid(T)(size_t length) {
T* ptr = cast(T*) GC.malloc(length * T.sizeof, blockAttribute!(T)());
return ptr[0..length];
}

unittest {
// Mostly just see if this instantiates.
auto foo = newVoid!uint(5);
foreach(i; 0..5) {
foo[i] = i;
}

foreach(i; 0..5) {
assert(foo[i] == i);
}
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 3384] New: toArray

2009-10-09 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3384

   Summary: toArray
   Product: D
   Version: 2.033
  Platform: Other
OS/Version: Windows
Status: NEW
  Keywords: patch
  Severity: enhancement
  Priority: P2
 Component: Phobos
AssignedTo: nob...@puremagic.com
ReportedBy: dsim...@yahoo.com


--- Comment #0 from David Simcha dsim...@yahoo.com 2009-10-09 10:16:21 PDT ---
Phobos needs an easy, efficient way of converting an arbitrary finite range
into an array, for example to allow for eager evaluation.  Below is a proposed
solution.  It relies on the existence of newVoid().  (See Bugzilla 3383.)

/**Converts any range to an array on the GC heap by the most efficient means
 * available.  If it is already an array, duplicates the range.*/
Unqual!(ElementType!(T))[] toArray(T)(T range) if(isInputRange!(T)) {
static if(isArray!(T)) {
// Allow fast copying by assuming that the input is an array.
return range.dup;
} else static if(hasLength!(T)) {
// Preallocate array, then copy.
auto ret = newVoid!(Unqual!(ElementType!(T)))(range.length);
static if(is(typeof(ret[] = range[]))) {
ret[] = range[];
} else {
size_t pos = 0;
foreach(elem; range) {
ret[pos++] = elem;
}
}
return ret;
} else {
// Don't have length, have to use appending.
Unqual!(ElementType!(T))[] ret;
auto app = appender(ret);
foreach(elem; range) {
app.put(elem);
}
return ret;
}
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---