Make index expressions in flatten expression consistent

The behavior is now consistent with wildcards.
Add more tests for the flattening operator