Skip to content

Commit 2117172

Browse files
dkorpelclaude
andcommitted
Fix #18342 - wstring literals cannot be implicitly converted to const(wchar)*
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 194278f commit 2117172

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

compiler/src/dmd/dcast.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,8 @@ MATCH implicitConvTo(Expression e, Type t)
823823
break;
824824
}
825825
}
826+
else if (tn.ty == tyn)
827+
return m; // e.g. "foo"w -> const(wchar)*
826828
break;
827829

828830
default:

compiler/test/runnable/implicit.d

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,19 @@ void test15778()
474474
static assert(!__traits(compiles, (ds[] = "a"w)));
475475
}
476476

477+
/***********************************/
478+
// https://github.com/dlang/dmd/issues/18342
479+
const(char)* cptr = "tic"c;
480+
const(wchar)* wcptr = "tac"w;
481+
immutable(dchar)* dcptr = "toe"d;
482+
483+
void test18342()
484+
{
485+
assert( cptr[0 .. 4] == "tic\0"c);
486+
assert(wcptr[0 .. 4] == "tac\0"w);
487+
assert(dcptr[0 .. 4] == "toe\0"d);
488+
}
489+
477490
/***********************************/
478491

479492
void main()
@@ -490,6 +503,7 @@ void main()
490503
testDIP29_5();
491504
testDIP29_6();
492505
test15778();
506+
test18342();
493507

494508
printf("Success\n");
495509
}

0 commit comments

Comments
 (0)