From d57474ab42947d0fc3be23063c83f0834c52f5d8 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 4 Oct 2008 11:54:17 +0100 Subject: [PATCH] In Delight, don't allow null as a dynamic array Use [] or "" for an empty array/string. Makes it clearer that there is no "null" array. --- dmd2/cast.c | 11 +++++++---- dmd2/expression.c | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dmd2/cast.c b/dmd2/cast.c index bb9b3c8..79492b3 100644 --- a/dmd2/cast.c +++ b/dmd2/cast.c @@ -380,16 +380,19 @@ MATCH NullExp::implicitConvTo(Type *t) if (t->invariantOf()->equals(type->invariantOf())) return MATCHconst; - // NULL implicitly converts to any pointer type or dynamic array + // (void *) NULL implicitly converts to any pointer type or dynamic array if (type->ty == Tpointer && type->nextOf()->ty == Tvoid) { if (t->ty == Ttypedef) t = ((TypeTypedef *)t)->sym->basetype; - if (t->ty == Tarray || - t->ty == Taarray || t->ty == Tmaybe || + + // Can always convert to these + if (t->ty == Taarray || t->ty == Tmaybe || t->ty == Tdelegate) return committed ? MATCHconvert : MATCHexact; - if (dUnchecked && (t->ty == Tpointer || t->ty == Tclass)) + + // Converting to dynamic arrays, pointers and classes not allowed in Delight + if (dUnchecked && (t->ty == Tarray || t->ty == Tpointer || t->ty == Tclass)) return committed ? MATCHconvert : MATCHexact; } diff --git a/dmd2/expression.c b/dmd2/expression.c index 8ea6eaa..2142b63 100644 --- a/dmd2/expression.c +++ b/dmd2/expression.c @@ -583,6 +583,7 @@ void functionArguments(Loc loc, Scope *sc, TypeFunction *tf, Expressions *argume if (nargs - i == 0) { arg = new NullExp(loc); + ((NullExp *) arg)->dUnchecked = true; break; } #endif -- 2.11.4.GIT