Fix check_scope to work on lists with array scopes

Adds tests for several scenarios. Squashed commits an rebased.