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
*
* Params:
* t = TypeAArray to convert
* Returns:
* t = found type
*/
* Find or create a TypeAArray with index and next without
* any head modifiers, tail `inout` is replaced with `const`
*
* Params:
* t = TypeAArray to convert
* Returns:
* t = found type
*/
Type makeNakedAssociativeArray(TypeAArray t)
{
Type tindex = t.index.toBasetype().nakedOf();
Type tnext = t.next.toBasetype().nakedOf();
Type tindex = t.index.toBasetype().nakedOf().substWildTo(MODFlags.const_);
Type tnext = t.next.toBasetype().nakedOf().substWildTo(MODFlags.const_);
if (tindex == t.index && tnext == t.next)
return t;

View file

@ -286,6 +286,19 @@ struct PropertyTable10106
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()
@ -295,6 +308,7 @@ int main()
test4523();
test3825();
test3825x();
testinout();
printf("Success\n");
return 0;