[Issue 3716] Regression (D2 only) with multi dimensional array literals
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jun 24 00:00:27 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3716
Don <clugdbug at yahoo.com.au> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #4 from Don <clugdbug at yahoo.com.au> 2010-06-24 00:00:18 PDT ---
This was caused by the change in 2.037:
"The type inferred from an ArrayLiteral is now a dynamic array, not a static
one."
typeMerge() in cast.c, needed to be modified in response, since [[]] is now of
type void[][] instead of void[][0]
I've patched this with a more general test for void array literals.
I'm not terribly happy with the patch, the dimensionality check seems
unnecessarily complicated.
// TEST CASES
void bug3716() {
auto k1 = true ? [1,2] : []; // OK
auto k2 = true ? [[1,2]] : [[]];
auto k3 = true ? [] : [[1,2]];
auto k4 = true ? [[[]]] : [[[1,2]]];
auto k5 = true ? [[[1,2]]] : [[[]]];
auto k6 = true ? [] : [[[]]];
static assert(!is(typeof(true ? [[[]]] : [[1,2]]))); // Must fail
}
----------
Index: cast.c
===================================================================
--- cast.c (revision 557)
+++ cast.c (working copy)
@@ -1499,6 +1499,30 @@
}
/**************************************
+ * Return true if e is an empty array literal with dimensionality
+ * equal to or less than type of other array.
+ * [], [[]], [[[]]], etc.
+ */
+bool isVoidArrayLiteral(Expression *e, Type *other)
+{
+ while (e->op == TOKarrayliteral && e->type->ty == Tarray
+ && (((ArrayLiteralExp *)e)->elements->dim == 1))
+ {
+ e = (Expression *)((ArrayLiteralExp *)e)->elements->data[0];
+ if (other->ty == Tsarray || other->ty == Tarray)
+ other = other->nextOf();
+ else
+ return false;
+ }
+ if (other->ty != Tsarray && other->ty != Tarray)
+ return false;
+ Type *t = e->type;
+ return (e->op == TOKarrayliteral && t->ty == Tarray &&
+ t->nextOf()->ty == Tvoid &&
+ ((ArrayLiteralExp *)e)->elements->dim == 0);
+}
+
+/**************************************
* Combine types.
* Output:
* *pt merged type, if *pt is not NULL
@@ -1616,7 +1640,7 @@
else if ((t1->ty == Tsarray || t1->ty == Tarray) &&
(e2->op == TOKnull && t2->ty == Tpointer && t2->nextOf()->ty ==
Tvoid ||
e2->op == TOKarrayliteral && t2->ty == Tsarray &&
t2->nextOf()->ty == Tvoid && ((TypeSArray *)t2)->dim->toInteger() == 0 ||
- e2->op == TOKarrayliteral && t2->ty == Tarray &&
t2->nextOf()->ty == Tvoid && ((ArrayLiteralExp *)e2)->elements->dim == 0)
+ isVoidArrayLiteral(e2, t1))
)
{ /* (T[n] op void*) => T[]
* (T[] op void*) => T[]
@@ -1630,7 +1654,7 @@
else if ((t2->ty == Tsarray || t2->ty == Tarray) &&
(e1->op == TOKnull && t1->ty == Tpointer && t1->nextOf()->ty ==
Tvoid ||
e1->op == TOKarrayliteral && t1->ty == Tsarray &&
t1->nextOf()->ty == Tvoid && ((TypeSArray *)t1)->dim->toInteger() == 0 ||
- e1->op == TOKarrayliteral && t1->ty == Tarray &&
t1->nextOf()->ty == Tvoid && ((ArrayLiteralExp *)e1)->elements->dim == 0)
+ isVoidArrayLiteral(e1, t2))
)
{ /* (void* op T[n]) => T[]
* (void* op T[]) => T[]
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list