Skip to content

Commit

Permalink
Merge pull request #10941 from BorisCarvajal/fix20130
Browse files Browse the repository at this point in the history
Fix Issue 20130 - ICE when casting from string to other array type du…
merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
  • Loading branch information
dlang-bot committed Mar 19, 2020
2 parents 7c22d24 + 8f24852 commit ff7c9ef
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
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)
{
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);
}

0 comments on commit ff7c9ef

Please sign in to comment.