Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1495 from yebblies/issue6408

Fix Issue 6408 - string[].init gives a wrong type
  • Loading branch information...
commit cd9ef35c402dbeb177343c7cea5b9ed4a5e6b94f 2 parents 52dfad2 + 064b041
@9rnsr 9rnsr authored
View
22 src/expression.c
@@ -9472,6 +9472,16 @@ Expression *SliceExp::semantic(Scope *sc)
Lagain:
UnaExp::semantic(sc);
e1 = resolveProperties(sc, e1);
+ if (e1->op == TOKtype && e1->type->ty != Ttuple)
+ {
+ if (lwr || upr)
+ {
+ error("cannot slice type '%s'", e1->toChars());
+ return new ErrorExp();
+ }
+ e = new TypeExp(loc, e1->type->arrayOf());
+ return e->semantic(sc);
+ }
e = this;
@@ -10004,6 +10014,18 @@ Expression *IndexExp::semantic(Scope *sc)
if (!e1->type)
e1 = e1->semantic(sc);
assert(e1->type); // semantic() should already be run on it
+ if (e1->op == TOKtype)
+ {
+ e2 = e2->semantic(sc);
+ e2 = resolveProperties(sc, e2);
+ Type *nt;
+ if (e2->op == TOKtype)
+ nt = new TypeAArray(e1->type, e2->type);
+ else
+ nt = new TypeSArray(e1->type, e2);
+ e = new TypeExp(loc, nt);
+ return e->semantic(sc);
+ }
if (e1->op == TOKerror)
goto Lerr;
e = this;
View
2  test/runnable/imports/bug846.d
@@ -2,7 +2,7 @@ module imports.bug846;
template ElemTypeOf( T )
{
- alias typeof(T[0]) ElemTypeOf;
+ alias typeof(T.init[0]) ElemTypeOf;
}
template removeIf_( Elem, Pred )
View
2  test/runnable/imports/test35a.d
@@ -2,7 +2,7 @@ module imports.test35a;
template ElemTypeOf( T )
{
- alias typeof(T[0]) ElemTypeOf;
+ alias typeof(T.init[0]) ElemTypeOf;
}
template removeIf_( Elem, Pred )
View
20 test/runnable/xtest46.d
@@ -946,6 +946,26 @@ void test48()
/***************************************************/
+// 6408
+
+static assert(!is(typeof(string[0..1].init)));
+static assert(is(typeof(string[].init) == string[]));
+static assert(is(typeof(string[][].init) == string[][]));
+static assert(is(typeof(string[][][].init) == string[][][]));
+
+static assert(is(typeof(string[1].init) == string[1]));
+static assert(is(typeof(string[1][1].init) == string[1][1]));
+static assert(is(typeof(string[1][1][1].init) == string[1][1][1]));
+
+static assert(is(typeof(string[string].init) == string[string]));
+static assert(is(typeof(string[string][string].init) == string[string][string]));
+static assert(is(typeof(string[string][string][string].init) == string[string][string][string]));
+
+template TT6408(T...) { alias T TT6408; }
+static assert(is(typeof(TT6408!(int, int)[].init) == TT6408!(int, int)));
+
+/***************************************************/
+
struct S49
{
static void* p;
Please sign in to comment.
Something went wrong with that request. Please try again.