Fix #21179 - Failure to convert const(T) to T after type is used in cast() (#21201)

This commit is contained in:
Dennis 2025-04-10 23:05:48 +02:00 committed by GitHub
parent bb25d82a3b
commit 1b34fea478
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 3 deletions

View file

@ -3266,9 +3266,19 @@ Type merge(Type type)
case Tsarray:
// prevents generating the mangle if the array dim is not yet known
if (!type.isTypeSArray().dim.isIntegerExp())
return type;
goto default;
if (auto ie = type.isTypeSArray().dim.isIntegerExp())
{
// After TypeSemantic, the length is always converted to size_t, but the parser
// usually generates regular integer types (e.g. in cast(const ubyte[2])) which
// it may try to merge, which then leads to failing implicit conversions as 2LU != 2
// according to Expression.equals. Only merge array types with size_t lengths for now.
// https://github.com/dlang/dmd/issues/21179
if (ie.type != Type.tsize_t)
return type;
goto default;
}
return type;
case Tenum:
break;

View file

@ -0,0 +1,11 @@
// https://github.com/dlang/dmd/issues/21179
void bigEndianToNative(ubyte[2] a) {}
void main()
{
ubyte[] arr;
const ubyte[2] bytes;
bigEndianToNative(bytes);
auto b = cast(const ubyte[2][]) arr;
}