Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue 20130 - ICE when casting from string to other array type du… #10941

Merged
merged 1 commit into from Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dmd/expressionsem.d
Expand Up @@ -7076,8 +7076,8 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
auto tFrom = t1b.nextOf();
auto tTo = tob.nextOf();

// https://issues.dlang.org/show_bug.cgi?id=19954
if (exp.e1.op != TOK.string_ || tTo.ty == Tarray)
// https://issues.dlang.org/show_bug.cgi?id=20130
if (exp.e1.op != TOK.string_ || !ex.isStringExp)
thewilsonator marked this conversation as resolved.
Show resolved Hide resolved
{
const uint fromSize = cast(uint)tFrom.size();
const uint toSize = cast(uint)tTo.size();
Expand Down
44 changes: 44 additions & 0 deletions test/runnable/test20130.d
@@ -0,0 +1,44 @@
// https://issues.dlang.org/show_bug.cgi?id=20130

void main() {
auto a1 = cast(char[]) "12345678";
auto a2 = cast(wchar[]) "12345678"; // Or cast(string|wstring|dstring).
auto a3 = cast(dchar[]) "12345678"; // Encoding conversion.
assert(a1.length == 8);
assert(a2.length == 8);
assert(a3.length == 8);

auto b1 = cast(char[]) "12345678"c;
auto b2 = cast(wchar[]) "12345678"c;
auto b3 = cast(dchar[]) "12345678"c;
assert(b1.length == 8);
assert(b2.length == 4);
assert(b3.length == 2);

auto c1 = cast(char[]) "12345678"w;
auto c2 = cast(wchar[]) "12345678"w;
auto c3 = cast(dchar[]) "12345678"w;
assert(c1.length == 16);
assert(c2.length == 8);
assert(c3.length == 4);

auto d1 = cast(char[]) "12345678"d;
auto d2 = cast(wchar[]) "12345678"d;
auto d3 = cast(dchar[]) "12345678"d;
assert(d1.length == 32);
assert(d2.length == 16);
assert(d3.length == 8);

auto a = cast(uint[]) "12345678";
auto b = cast(uint[]) "12345678"d;
auto c = cast(uint[]) "12345678"w;
auto d = cast(const char[5][]) "12345";
auto e = cast(const wchar[2][]) "12345678";
immutable f = cast(immutable(uint)[]) "123456789012";
assert(a.length == 2);
assert(b.length == 8);
assert(c.length == 4);
assert(d.length == 1);
assert(e.length == 2);
assert(f.length == 3);
}