Skip to content

Commit

Permalink
Merge pull request #7448 from ntrel/qual-cast
Browse files Browse the repository at this point in the history
Issue 9631 - Error message not using fully qualified name (part 3)
merged-on-behalf-of: Mike Franklin <JinShil@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Dec 20, 2017
2 parents 806bb1d + 27b272c commit 97e51d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/dmd/dcast.d
Expand Up @@ -1560,7 +1560,9 @@ extern (C++) Expression castTo(Expression e, Scope* sc, Type t)
{
if (t1b.size(e.loc) == tob.size(e.loc))
goto Lok;
e.error("cannot cast expression `%s` of type `%s` to `%s` because of different sizes", e.toChars(), e.type.toChars(), t.toChars());
auto ts = toAutoQualChars(e.type, t);
e.error("cannot cast expression `%s` of type `%s` to `%s` because of different sizes",
e.toChars(), ts[0], ts[1]);
result = new ErrorExp();
return;
}
Expand Down Expand Up @@ -2469,7 +2471,9 @@ extern (C++) Expression castTo(Expression e, Scope* sc, Type t)
return;
}
}
e.error("cannot cast expression `%s` of type `%s` to `%s`", e.toChars(), tsa ? tsa.toChars() : e.type.toChars(), t.toChars());
auto ts = toAutoQualChars(tsa ? tsa : e.type, t);
e.error("cannot cast expression `%s` of type `%s` to `%s`",
e.toChars(), ts[0], ts[1]);
result = new ErrorExp();
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/fail_compilation/bug9631.d
Expand Up @@ -40,3 +40,21 @@ void equal()
auto y = tem!().S();
bool b = x == y;
}

/*
TEST_OUTPUT:
---
fail_compilation/bug9631.d(55): Error: cannot cast expression `x` of type `bug9631.S` to `bug9631.tem!().S` because of different sizes
fail_compilation/bug9631.d(58): Error: cannot cast expression `ta` of type `bug9631.tem!().S[1]` to `bug9631.S[1]` because of different sizes
fail_compilation/bug9631.d(59): Error: cannot cast expression `sa` of type `S[1]` to `S[]` since sizes don't line up
---
*/
void test3()
{
S x;
auto y = cast(tem!().S)x;

tem!().S[1] ta;
S[1] sa = cast(S[1])ta;
auto t2 = cast(tem!().S[])sa;
}

0 comments on commit 97e51d1

Please sign in to comment.