Skip to content

Commit

Permalink
Check the cast from class type to dynamic or static array type
Browse files Browse the repository at this point in the history
It's a reverse direction of issue 10646 case.
  • Loading branch information
9rnsr committed Jan 14, 2015
1 parent c1462de commit 2cd314d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/expression.c
Expand Up @@ -9582,8 +9582,9 @@ Expression *CastExp::semantic(Scope *sc)
goto Lfail;
}

// Bugzilla 10646: Tclass <-- (T[] or T[n])
if (tob->ty == Tclass && (t1b->ty == Tarray || t1b->ty == Tsarray))
// Bugzilla 10646: Tclass <--> (T[] or T[n])
if (tob->ty == Tclass && (t1b->ty == Tarray || t1b->ty == Tsarray) ||
t1b->ty == Tclass && (tob->ty == Tarray || tob->ty == Tsarray))
{
goto Lfail;
}
Expand Down
20 changes: 10 additions & 10 deletions test/fail_compilation/fail_casting.d
Expand Up @@ -34,22 +34,22 @@ void test9904()
/*
TEST_OUTPUT:
---
fail_compilation/fail_casting.d(47): Error: cannot cast expression csd of type Object[] to object.Object
fail_compilation/fail_casting.d(48): Error: cannot cast expression css of type Object[2] to object.Object
fail_compilation/fail_casting.d(46): Error: cannot cast expression x of type Object[] to object.Object
fail_compilation/fail_casting.d(47): Error: cannot cast expression x of type Object[2] to object.Object
fail_compilation/fail_casting.d(49): Error: cannot cast expression x of type object.Object to Object[]
fail_compilation/fail_casting.d(50): Error: cannot cast expression x of type object.Object to Object[2]
---
*/


void test10646()
{
Object[] csd;
Object[2] css;
{ auto c1 = cast(Object)csd; }
{ auto c2 = cast(Object)css; }
// T[] or T[n] --> Tclass
{ Object[] x; auto y = cast(Object)x; }
{ Object[2] x; auto y = cast(Object)x; }
// T[] or T[n] <-- Tclass
{ Object x; auto y = cast(Object[] )x; }
{ Object x; auto y = cast(Object[2])x; }
}



/*
TEST_OUTPUT:
---
Expand Down

0 comments on commit 2cd314d

Please sign in to comment.