substitute inout with const in key and value types

This commit is contained in:
Rainer 2025-02-18 08:09:51 +01:00
parent 76f066303d
commit 7496f54fc4
2 changed files with 24 additions and 9 deletions

View file

@ -200,17 +200,18 @@ TypeInfoDeclaration getTypeInfoAssocArrayDeclaration(TypeAArray t, Scope* sc)
} }
/****************************************** /******************************************
* Find or create a TypeAArray with index and next without any modifiers * Find or create a TypeAArray with index and next without
* * any head modifiers, tail `inout` is replaced with `const`
* Params: *
* t = TypeAArray to convert * Params:
* Returns: * t = TypeAArray to convert
* t = found type * Returns:
*/ * t = found type
*/
Type makeNakedAssociativeArray(TypeAArray t) Type makeNakedAssociativeArray(TypeAArray t)
{ {
Type tindex = t.index.toBasetype().nakedOf(); Type tindex = t.index.toBasetype().nakedOf().substWildTo(MODFlags.const_);
Type tnext = t.next.toBasetype().nakedOf(); Type tnext = t.next.toBasetype().nakedOf().substWildTo(MODFlags.const_);
if (tindex == t.index && tnext == t.next) if (tindex == t.index && tnext == t.next)
return t; return t;

View file

@ -286,6 +286,19 @@ struct PropertyTable10106
CodepointSet10106[string] table; CodepointSet10106[string] table;
} }
/************************************************/
// strip inout in key and value types
void testinout()
{
inout(long) func1(inout(long[][int]) aa)
{
return aa[0][0];
}
long[][int] a = [ 0 : [42] ];
long b = func1(a);
assert(b == 42);
}
/************************************************/ /************************************************/
int main() int main()
@ -295,6 +308,7 @@ int main()
test4523(); test4523();
test3825(); test3825();
test3825x(); test3825x();
testinout();
printf("Success\n"); printf("Success\n");
return 0; return 0;