Skip to content

Commit

Permalink
Fix ambiguous type deduction around hex strings (#20679)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Jan 10, 2025
1 parent d3f2ee3 commit b237d03
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/src/dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,12 @@ MATCH implicitConvTo(Expression e, Type t)
if (!tn.isConst() && !tn.isImmutable())
return MATCH.nomatch;
m = MATCH.constant;

// After converting e.g. ubyte[] to const(ubyte)[], don't change
// to MATCH.convert, return MATCH.constant
// https://github.com/dlang/dmd/issues/20635
if (e.type.ty == t.ty && e.type.nextOf().ty == tn.ty)
return m;
}
if (e.type != t && e.hexString && tn.isintegral && (tn.size == e.sz || (!e.committed && (e.len % tn.size) == 0)))
{
Expand Down
8 changes: 8 additions & 0 deletions compiler/test/runnable/literal.d
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,16 @@ void testHexstring()
static immutable ulong[] z0 = cast(immutable ulong[]) x"1111 1111 1111 1111 0000 000F 0000 0000";
static immutable ulong[] z1 = [0x1111_1111_1111_1111, 0x0000_000E_0000_0000];
static assert(z0 !is z1);

// https://github.com/dlang/dmd/issues/20635
f20635(cast(ubyte[]) x"00");
f20635(cast(const ubyte[]) x"00");
f20635(cast(immutable ubyte[]) x"00");
}

void f20635(const ubyte[] value){}
void f20635(const string value){}

/***************************************************/

int main()
Expand Down

0 comments on commit b237d03

Please sign in to comment.