Type pattern incorrectly checks existence of variables
int[n:outer_shape] myTake1(int[n] outer_shape, int[d:shp] array)
| (n <= d && all(outer_shape <= {[i] -> shp[i] | [i] < [n]}))
{
return { iv -> array[iv] | iv < outer_shape };
}
Gives an error:
Condition contains an identifier 'i' that is not defined by an argument or a type pattern.
The issue is that when we encounter a type pattern condition, we check all identifiers within it to decide if that condition should be part of the pre-check or the post-check.
We take all identifiers indiscriminately, which means that we also check [i]
in the tensor comprehension.
To fix this we need to keep track of locally defined variables, such as i
.
Or alternatively, we just ignore variables that are not defined.
The type checker will eventually figure out that this variable does not exist anyways.
Depending on the quality of that error message we might just want to go for that approach, as it keeps the traversal simple, and also keeps the error messages consistent.